UNIVERSITY INSTITUTE OF COMPUTING
MASTERS OF COMPUTER APPLICATIONS
PYTHON PROGRAMMING
21CAH-645
DISCOVER . LEARN . EMPOWER
1
Python Data Types
Text Type str
Numeric Types int, float, complex
Sequence Types list, tuple, range
Mapping Type Dict
Set Types set, frozenset
Boolean Type Bool
Binary Type bytes, bytearray, memoryview
2
Setting Data Type in Python
In Python, the data type is set when you assign a value to a variable:
Example Data Type
x = "Hello World" str
x = 20 int
x = 20.5 float
x = 1j complex
x = ["apple", "banana", "cherry"] list
x = ("apple", "banana", "cherry") tuple
x = range(6) range
3
Setting Data Type in Python
Example Data Type
x = {"name" : "John", "age" : 36} dict
x = {"apple", "banana", "cherry"} set
x = frozenset({"apple", "banana", "cherry"}) frozenset
x = True bool
x = b"Hello" bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview
4
Setting Specific Data Type in Python
Example Data Type
x = str("Hello World") str
x = int(20) int
x = float(20.5) float
x = complex(1j) complex
x = list(("apple", "banana", "cherry")) list
x = tuple(("apple", "banana", "cherry")) tuple
x = range(6) range
5
Setting Specific Data Type in Python
Example Data Type
x = dict(name : "John", age : 36} dict
x = set(("apple", "banana", "cherry")) set
x = frozenset(("apple", "banana", "cherry")) frozenset
x = bool(5) bool
x = bytes(5) bytes
x = bytearray(5) bytearray
x = memoryview(bytes(5)) memoryview
6
Python Basics
Operation Output
● 2+3 5
● 9–8 1
● 4*6 24
● 8/4 2.0 (Why)
● 5/2 2.5
● 5 // 2 2 (integer or floor division )
● 8 + 9 -10 7 (multiple operation)
● 8+2*3 14
● (8 + 2) * 3 30
● 2 ** 3 8 (Power of)
● 10 % 3 1 (remainder) 7