Python Variables — Python Technical Interview Questions & Answers
Python Variables
Python Variables
- A variable is a name pointing at a value. age = 21 creates the name age and binds it to 21. No type word on the left. The type lives on the object. Later age = "twenty" is allowed — dynamic typing — but jumping types in real code confuses readers.
- Names: letters, digits, underscore. Cannot start with a digit. Cannot be a keyword. Style is snake_case: student_name. a, b = 1, 2 unpacks two values. Using a name before assignment → NameError. That is the first crash most freshers see.
- Python Variables — output: Pune · age 21. Two real variables.
Technical Interview Tip: Assignment creates the binding; types live on objects.
Code Examples for Python Variables
Example
# Variables
age = 21
city = "Pune"
print(city, "· age", age)
Python Variables — output: Pune · age 21. Two real variables.
How to Explain Python Variables to an Interviewer
Explain Variables as if you are teaching a junior — definition, then one tiny script.
name = value. snake_case. No keyword names.
What does the example print, and why?
Python Variables — output: Pune · age 21
What mistake do freshers make with Variables?
NameError if used before assign.