0% found this document useful (0 votes)
10 views43 pages

Day2 Datatypes1 Cs

Uploaded by

iamkyros
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views43 pages

Day2 Datatypes1 Cs

Uploaded by

iamkyros
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

PYTHON DATA

TYPES
Python Character Set

Data types
variables

Identifiers
keywords
String operators

functions Comments

punctuators

Blocks and indentation


Variable
• A variable is name that is used to store data.it can be used to store different
kinds of data.
• Variable in Python refers to an object — an item or element that is stored in
the memory.
• Value of a variable can be a string (e.g., ‘m’, ‘hello world’), numeric (e.g.,
66) or any combination of alphanumeric characters (CD67).
• In Python we can use an assignment statement to create new variables and
assign specific values to them.
• Example :
• gender = ‘M’
• message = "Keep Smiling"
• price = 987.9
Sum.py

num1=34
num2=24 Num1,num2 and
sum=num1+num2
print(sum)
sum are variables
here

I don’t want to take data 34 and 24 everytime..

what should I do to take values from keyboard ?


• num1=input("enter first number")
• num2=input("enter second number")

• a=int(num1)
• b=int(num2)
Now…
• sum=a+b
what is that int here?
• print(sum)
Data type

• A data type or simply a type is a property of data, that tells the


language processor (compiler, interpreter) how we are going to use this
data.
• data types tell the meaning of data, how that data is going to store in
memory, and what different operations can be performed on it.
• In Python programming language, if we have to store any value in a
variable, then data type role comes into play.
• when we are storing a value in a variable, we have to use the same types
of data as the type of variable. Each value belongs to some data types in
Python.
• Data type identifies the type of data which a variable can hold and the
operations that can be performed on those data.
python offers the following built-in core
data types -:
1.Numbers
2.String
3.List
4.Tuple
5.Dictionary
Numbers data type
String data type
String Data type

• A string is the Group of characters. These characters


may be digits alphabets or special characters including
spaces.
• Python allows you to have two types of string
• Single Line: enclosing text in single quotes or double quotes
• Multi Line : enclosing text in triple quotes
List data type
List

• Python knows a number of compound data types, used to group


together other values. The most versatile is the list,
• which can be written as a list of comma-separated values
(items) between square brackets.
• Lists might contain items of different types, but usually the
items all have the same type.
• Lists can be changed/modified/mutate. This means List is a
Mutable Data type.
• A list in python represents a comma-separated value of any
datatype between the square bracket.
Let’s take break
from these data
types

Now its programming time


TIME LIMIT : 30 mins

1. Write a python program to obtain three numbers and print their sum
(threesum.py)
2. Write a python program to obtain length and breadth of a rectangle and
calculate its area (rectarea.py)
3. Write a python program to calculate profit and profit percentage from
the sales of good that you made(profit.py)
4. Write a program for students it will take five subjects marks and find the
total of all the subjects marks also find the percentage of the student.
(result.py)
5. Write a program that asks for your height in centimeters and then
convert your height to feet and inches(1 foot=12inches,1 inch=2.54 cm)
(height.py)
tuple data type
TUPLE

• Tuples are a sequence of values of any type and are indexed by integers.
• They are immutable.
• Tuples are enclosed in ().
• Though tuples may seem similar to lists, they are often used in different situations and
for different purposes.
• Tuples are immutable, and usually contain a heterogeneous sequence of elements
• Lists are mutable, and their elements are usually homogeneous and are accessed by
iterating over the list.
• A special problem is the construction of tuples containing 0 or 1 items: the syntax has
some extra quirks to accommodate these.
• Empty tuples are constructed by an empty pair of parentheses; a tuple with one item is
constructed by following a value with a comma
• The statement t = 12345, 54321, 'hello!' is an example of tuple packing: the values
12345, 54321 and 'hello!' are packed together in a tuple. The reverse operation is also
possible:
Sets data type
sets

• Python also includes a data type for sets. A set is an unordered collection with no
duplicate elements.
• Basic uses include membership testing and eliminating duplicate entries.
• Set objects also support mathematical operations like union, intersection, difference
etc
• Curly braces or the set() function can be used to create sets.
• to create an empty set you have to use set(), not {}
Mapping:
Dictionaries
data type
Mapping - > Dictionaries

• Mapping: This data type is unordered and mutable. Dictionaries fall under Mappings.
• Dictionaries: It can store any number of python objects. What they store is a key -
value pairs, which are accessed using key.
• Dictionary is enclosed in curly brackets ({}).

You might also like