A Python variable is a named label attached to an object in memory, created the moment you assign a value with =. You never need to declare a variable type in advance because Python tracks the type on the value itself.
Because variables hold references rather than fixed boxes, you can rebind a name to a new value at any time. Keeping variable types consistent inside a function still makes your code far easier to debug.
You can assign single values, chain one value to multiple names, or unpack a sequence into separate variables on one line.
# Standard assignment
customer_id = 4082
account_active = True
# Tuple unpacking
width, height = 1920, 1080
first_name, last_name = "Nadia", "Karim"
print(customer_id, width, height, first_name)
Unpacking swaps two variables without a temporary variable: a, b = b, a.
Python enforces strict syntax rules for identifier names and adds community style standards in PEP 8:
a-z, A-Z) or underscore _, never a digit.user_age, item2).class, for, return, or import.snake_case for variables and UPPER_SNAKE_CASE for module-level constants like MAX_UPLOAD_MB = 25.list, str, id, or sum overrides Python's built-in name in that scope.b = a on a list points both names to the same list, so mutating b changes a too.data from a raw string to a dictionary mid-function often hides bugs.Pass the variable to the built-in type() function, such as type(customer_id), which prints <class 'int'>.
Yes. userScore and userscore refer to completely different variables in Python.
Use the del statement (del temp_cache) to remove the name binding from the current namespace.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.
You've completed this section! Take a quick 5-question quiz to check your understanding.