Python variables are names bound to objects—no int x = 5 type declarations like Java. Types live on objects; names can rebind to different types at runtime, similar to JavaScript but with stricter rules (e.g., no implicit string+number concat).
Common built-in types
int,float— numbers (arbitrary-precision ints)str— Unicode text, immutablebool—TrueorFalse(capitalized)None— absence of value, likenullin JS
Assignment and type()
count = 10
ratio = 0.75
name = "Ada"
ok = True
print(type(count), type(name))
Use type() or isinstance() at runtime. Optional static type hints come later—compare with C# compile-time checks.
Important interview questions and answers
- Q: Dynamic vs static typing?
A: Python resolves types at runtime on objects; Java/C# enforce variable types at compile time. - Q: Mutable vs immutable scalars?
A:int,float,str,tupleare immutable;list,dict,setare mutable.
Self-check
- What does
type(3.14)return? - Can a name rebind from int to str?
Pitfall: Names bind to objects—a = b for lists aliases the same list, unlike copying value types in C# structs.
Interview prep
- Dynamic typing meaning?
Types attach to objects; names can rebind to different types—checked at runtime, optionally annotated for static tools.
- None vs False?
Noneis the null sentinel;Falseis a boolean—both are falsy but distinct objects.