Python Variables and Data Types
In Python, variables are used to store data values. Python is dynamically typed, meaning
you do not need to declare the type of a variable explicitly. The type is assigned
automatically when a value is stored.
Type Name Example Explanation
int Integer age = 25 Whole numbers,
positive or negative,
without decimals.
float Floating-point pi = 3.1416 Numbers with
decimals, for
scientific/engineeri
ng calculations.
complex Complex number z = 2 + 3j Numbers with real
and imaginary parts.
str String name = "Rabya" Text values inside
quotes (single or
double).
bool Boolean flag = True Logical values: True
or False.
list List (ordered, marks = [85, 90, 78] Collection of items,
mutable) can be changed,
keeps order.
tuple Tuple (ordered, point = (2, 3) Like a list, but
immutable) cannot be changed
once created.
set Set (unordered, items = {1, 2, 3} Unordered
unique) collection with no
duplicates.
dict Dictionary student = {"name": Key–value pairs, like
"Ali", "age": 20} a mini database.
NoneType None x = None Special type
meaning 'no value'.