Definition
📌 Variables
Python variables don't need a declared type — you simply assign a value, and Python figures out the type automatically.
Syntax
syntax
variableName = valueExample
py
age = 20
price = 49.99
name = "CodeyHub"
print(name, age, price)
print(type(age))Output
outputCodeyHub 20 49.99
<class 'int'>
Important Points
- No type keyword is needed — Python infers the type from the assigned value.
- A variable can be reassigned to hold a different type of value later in the same script.
- Variable names are case-sensitive and can contain letters, digits, and underscores (not starting with a digit).
- Use
type(variable)to check what type Python assigned.
Common Mistakes
- Assuming Python variables are typeless — the value has a type, only the variable itself is untyped.
- Using a variable before assigning it any value, causing a
NameError. - Mixing incompatible types in an operation, like adding a string and a number directly.
Interview Tip
🎯 Before your interview
Be ready to explain "dynamic typing" in one sentence: the type is checked at runtime based on the value, not declared ahead of time by the programmer.
