Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — Data Types

Lesson 9 of 50 in the free Python Programming notes on Siksha Sarovar, written by Rohit Jangra.

Data Types in Python

Python has several built-in data types, broadly grouped as:

CategoryTypes
Numericint, float, complex
Sequencestr, list, tuple, range
Mappingdict
Setset, frozenset
Booleanbool
Binarybytes, bytearray, memoryview
NoneNoneType

Numeric Types

a = 10          # int      — whole numbers
b = 3.14        # float    — decimal numbers
c = 2 + 3j      # complex  — real + imaginary part
print(type(a), type(b), type(c))

Boolean

flag = True
print(type(flag))    # <class 'bool'>
print(True + True)   # 2  -> bool is a subtype of int

Sequence Types

s = "Python"                 # str   — ordered, immutable characters
lst = [1, 2, 3]                # list  — ordered, mutable
tup = (1, 2, 3)                # tuple — ordered, immutable
r = range(5)                   # range — sequence of numbers

Mapping Type

d = {"name": "Ravi", "age": 21}   # dict — key-value pairs

Set Types

st = {1, 2, 3}                 # set        — unordered, unique, mutable
fs = frozenset({1, 2, 3})      # frozenset  — unordered, unique, immutable

None Type

x = None
print(type(x))   # <class 'NoneType'>

Type Conversion (Casting)

print(int("25"))       # 25   (str -> int)
print(float(10))       # 10.0 (int -> float)
print(str(3.14))       # '3.14' (float -> str)
print(list("abc"))     # ['a', 'b', 'c']
print(bool(0))          # False
print(bool(1))          # True

type() and isinstance()

x = 5
print(type(x) == int)       # True
print(isinstance(x, int))   # True (preferred, supports inheritance)