In Python, a variable is just a name that points to an object in memory. We don’t need to declare types — Python figures it out at runtime. This is called dynamic typing.
Creating Variables
There’s no let, const, or var keyword. We just assign a value and Python handles the rest.
name = "Manish" # str
age = 25 # int
height = 5.9 # float
is_active = True # bool
nothing = None # NoneType
The same variable can point to different types at different times. Python won’t complain.
x = 10 # x is an int
x = "hello" # now x is a str — totally fine
Built-in Data Types
Python comes with these core types out of the box:
- int — whole numbers like
42,-7,1_000_000(underscores for readability) - float — decimal numbers like
3.14,-0.5 - complex — numbers with a real and imaginary part like
3 + 4j(rarely used outside math) - bool —
TrueorFalse(capitalized, and they’re actually subclasses ofint) - str — text like
"hello"or'world' - None — Python’s version of “nothing” or “no value”
Checking Types
We can use type() to see what type something is, and isinstance() to check if it belongs to a type.
x = 42
print(type(x)) # <class 'int'>
print(isinstance(x, int)) # True
# isinstance can check multiple types at once
print(isinstance(x, (int, float))) # True
The difference? type() gives us the exact type, while isinstance() also respects inheritance. Since bool is a subclass of int, isinstance(True, int) returns True.
Naming Conventions
Python has strong conventions (from PEP 8):
- Variables and functions —
snake_case(e.g.,user_name,total_count) - Constants —
UPPER_SNAKE_CASE(e.g.,MAX_RETRIES,API_KEY) - Classes —
PascalCase(e.g.,UserProfile) - Names starting with
_are “private by convention” (not enforced) - Names starting with
__trigger name mangling in classes
# Good
user_age = 25
MAX_CONNECTIONS = 100
# Avoid
userAge = 25 # camelCase is not Pythonic
x = 25 # too vague
In simple language, Python variables are just labels we stick on objects. The object knows its own type — the variable doesn’t care.