6. Python - Data Types
6. Python - Data Types
Table of Contents
✓ A data type represents the type of the data stored into a variable or
memory.
emp_id = 1
name = "Daniel"
salary = 10000.56
Output
My employee id is: 1
My name is: Daniel
My salary is: 10000.56
Note
✓ By using type(p) function we can check the data type of each variable.
2. type(p) function
emp_id = 1
name = "Daniel"
salary = 10000.56
Output
My employee id is: 1
My name is: Daniel
My salary is: 10000.56
✓ The data types which are already existing in python are called built-in
data types.
1. Numeric types
o int
o float
1. Numeric types
✓ The numeric types represent numbers, these are divided into three
types,
1. int
2. float
3. complex
a = 20
print(a)
print(type(a))
output
20
<class ‘int’>
b = 9999999999999999999
print(b)
print(type(b))
output
9999999999999999999
<class ‘int’>
salary = 10000.56
print(salary)
print(type(salary))
Output
10000.56
<class 'float'>
Make a note
o True as 1
o False as 0
a = True
b = False
print(a)
print(b)
output
True
False
✓ None data type represents an object that does not contain any value.
✓ If any object having no value, then we can assign that object with None
data type.
a = None
print(a)
print(type(a))
output
None
<class ‘NoneType’>
Note
✓ A function and method can return None data type.
✓ This point we will understand more in functions and oops chapters.
4. Sequences in Python
1. string
2. list
3. tuple
4. set
5. dict
6. range
Make a note
✓ Regarding sequences like string, list, tuple, set and dict we will
discuss in upcoming chapters
▪ Python String chapter
▪ Python List Data Structure chapter
▪ Python Tuple Data Structure chapter
▪ Python Set Data Structure chapter
▪ Python Dictionary Data Structure chapter
name1 = 'Daniel'
name2 = "Daniel"
name3 = '''Daniel'''
name4 = """Daniel"""
print(name1)
print(name2)
print(name3)
print(name4)
print(type(name1))
print(type(name2))
print(type(name3))
print(type(name4))
Output
Daniel
Daniel
Daniel
Daniel
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
10 | P a g e 6.PYTHON-DATA TYPES
Data Science – Python Data Types
Output
Output
11 | P a g e 6.PYTHON-DATA TYPES
Data Science – Python Data Types
Output
Output
12 | P a g e 6.PYTHON-DATA TYPES
Data Science – Python Data Types
1. range(p) function
a = range(5)
print(a)
print(type(a))
Output
range(0, 5)
<class ‘range’>
Note:
13 | P a g e 6.PYTHON-DATA TYPES
Data Science – Python Data Types
a = range(1, 10)
print(a)
Output
range(1, 10)
Note:
✓ If we provide range(1, 10), then range object holds the values from 1 to 9
14 | P a g e 6.PYTHON-DATA TYPES
Data Science – Python Data Types
r = range(10, 15)
for value in r:
print(value)
output
10
11
12
13
14
15 | P a g e 6.PYTHON-DATA TYPES