Python / Core Python Fundamentals Interview Questions
How do variables work in Python, and what does dynamic typing mean?
In Python a variable is simply a name that points to an object in memory. You do not declare the type — you just assign a value and Python figures out the type at runtime. That is what dynamic typing means: the type is attached to the object, not to the name.
x = 10 # x points to an int object x = 'hello' # now x points to a str object â perfectly legal x = [1, 2, 3] # now x points to a list print(type(x)) #
Each assignment rebinds the name to a new object; the old object is garbage-collected when nothing else references it. This is why Python variables behave more like labels than typed containers.
Dynamic typing provides flexibility but can hide bugs that a static-type compiler would catch at build time. Python 3.5+ addresses this with optional type hints (PEP 484) that tools like mypy can check without changing runtime behaviour.
Naming conventions: use lowercase with underscores (snake_case) for variables and functions, ALL_CAPS for module-level constants. Python is case-sensitive, so count and Count are two different names.
More Related questions...