Python Data Types
Python Data Types
1. Numbers
2. String
3. List
4. Tuple
5. Set
6. Dictionary
NUMBERS
This data type stores numeric values. Numbers object are created when you assign
a value to them.
Python supports following numerical types:
Int
Float
Complex
Example :
a,b,c = 1, 1.5, 2+9j
print(“a : ”,a)
print(“b : ”,b)
print(“c : ”,c)
Mathematical Functions on Numbers
Function Description
abs(x) Returns the absolute value of x
sqrt(x) Finds square root of x
ceil(x) Finds the smallest integer not less than x
floor(x) Finds the greatest integer not greater than x
pow(x,y) Finds x raised to y
exp(x) Returns exponential of x
fabs(x) Returns absolute value of x
log(x) Finds natural log of x
log10(x) Finds log to the base 10 of x
max(x1,x2,….,xn) Returns largest of its arguments
min(x1,x2,….,xn) Returns smallest of its arguments
round(x) x will be rounded to n digits if x is decimal
number
Mathematical Functions on Numbers :
# s4 = {1, 2, [3,4]} # Set4 is not valid because set can not have
mutable items
# print(“Set 4 : ”, s4) # Hence not permitted.
dict = {}
dict[‘one’] = “This is One”
dict[2] = “This is Two”
small_dict = {‘Name’:’John’, ‘Code’:’6734’, ‘Dept’:’sales’}
dict1 = {‘Name’:’Tom’,’Age’:20,’Height’:160}
print(dict1)
dict1[‘Age’] = 25 # Updating
existing key-value pair
print(‘Dictionary after update : ’, dict1)
dict1 = {‘Name’:’Tom’,’Age’:20,’Height’:160}
print(dict1)
del dict1[‘Age’] # Deleting key-value
pair ‘Age’:20
print(“Dictionary after deletion : ”, dict1)
dict1.clear() # Clearing
entire dictionary
print(dict1)