Data Types:
Data types are means to identify the type of data and associated operations
of handling it. In Python we are not required to explicitly declare a variable
with its type. Whenever we declare a variable with some value, Python
automatically allocates the relevant data type associated with it. Hence, the
data type of a variable is according to the value it holds.
Eg.
>>> a= 10
The above statement signifies ‘a’ to be of integer type since it has been
assigned an integer value 10.
Data type
Number None Sequences Sets Mapping
Floating
Integer Complex String Tuple List Dictionary
Point
Boolean
Number or Numeric Data Type
Number data type is used to store numeric values.
Integer: to store whole numbers. They can be positive or negative.
Eg. 12, 30, 100, ‐10
o Boolean: Boolean data type is used in situation where comparison to be
made always result in either True(1) or False(0).
Float/ Floating Point: to store real numbers. They can be represented in
scientific notations where the uppercase or lowercase letter ‘e’ signifies
the 10th power.
>>>3.8e2
380.0
>>>3.8e3
3800.0
>>>0.2534e2
25.34
String: A string data type lets you hold string data. Characters are written
inside simple quotation marks (Single or double). Eg. ‘Amit’, ‘Boy’, “ford”
etc.
List: A list in Python represents a list of comma‐separated values of any
data type between square brackets.
Eg. a=[‘a’, ’e’, ‘i’, ‘o’, ‘u’]
b=[‘age’, 10.5, 20,’a’, [3,4,5,6],45]
List can be assigned to variables just like other data types and you can
also change individual elements of a list.
Tuples: Tuples are represented as list of comma‐separated values of any
data type within parentheses.
Eg. a=(‘a’, ’e’, ‘i’, ‘o’, ‘u’)
b=(‘age’, 10, 20, 23, 45)
Tuples like list can be assigned to variable but individual elements of
tuples cannot be modified.
Dictionary: Dictionary is an unordered set of comma‐separated
key:value pairs, within {}. In a dictionary no two keys can be the same.
Eg.
>>>a={‘y’: 2 ,‘x’: 1, ‘z’: 3} Here ‘x’: 1 is a key: value pair
>>>a[‘x’]
1
>>>a[‘z’]
3
>>> print(a['x'])
1
>>> a['x']=10
>>> print(a)
{'x': 10, 'y': 2, 'z': 3}