Day2 Datatypes1 Cs
Day2 Datatypes1 Cs
TYPES
Python Character Set
Data types
variables
Identifiers
keywords
String operators
functions Comments
punctuators
num1=34
num2=24 Num1,num2 and
sum=num1+num2
print(sum)
sum are variables
here
• a=int(num1)
• b=int(num2)
Now…
• sum=a+b
what is that int here?
• print(sum)
Data type
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 ({}).