100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

Variables in Python

Learn how Python variables work as dynamically-typed name bindings, how to create and reassign them, and the rules for naming them correctly.

Basics & Data TypesBeginner8 min readJul 7, 2026
Analogies

1. Introduction

A variable in Python is a name that refers to a value stored in memory. Unlike many other languages, Python does not require you to declare a variable's type before using it — you simply assign a value with the = operator and Python figures out the type automatically. This makes Python code concise and beginner-friendly, but it also means you need to understand how names are bound to objects to avoid subtle bugs.

🏏

Cricket analogy: A cricket team doesn't fix a player's batting position for life — captains reassign 'opener' to whoever suits the situation, just as Python lets a variable name be assigned any value without declaring its type upfront.

Variables matter because they let you store, reuse, and update data as a program runs — from simple counters in a loop to complex objects passed between functions. Mastering variable assignment is the first real step toward writing working Python programs.

🏏

Cricket analogy: A scoreboard's run tally is a variable that updates ball by ball throughout an innings and gets passed to the commentary team, just as Python variables store and update data as a program runs.

2. Syntax

python
x = 5
y = "hello"
z = 3.14

# multiple assignment
a, b, c = 1, 2, 3

# same value to multiple names
p = q = 100

3. Explanation

In Python, a variable is really just a label pointing to an object in memory; the = sign creates or updates that binding rather than copying data into a fixed-type box. Because of this, the same variable name can be rebound to a completely different type of object later in the program — this is called dynamic typing.

🏏

Cricket analogy: A team's 'captain' armband is just a label passed to whichever player currently holds it — reassigning it to a new player doesn't copy the old captain's stats, just as Python's '=' rebinds a name to a new object.

Python also supports multiple assignment in a single line, either giving several names their own values (a, b, c = 1, 2, 3) or binding several names to the exact same object (p = q = 100). Understanding the distinction matters most for mutable objects like lists, where two names pointing to the same object will both see changes made through either name.

🏏

Cricket analogy: Assigning three batsmen their individual scores at once (a, b, c = 45, 30, 12) is like separate scorecards, but if two commentators share the same live-scoring app object, an update from one shows up for both instantly.

Variable names in Python are case-sensitive (age and Age are different variables), and by convention (PEP 8) should use lowercase snake_case such as user_name rather than camelCase.

Common misconception: reassigning a variable to a new type is not an error. x = 5 followed by x = "five" is perfectly legal — Python does not lock a variable to the type of its first value, because the variable is only a reference, not a typed storage slot.

4. Example

python
name = "Alice"
age = 30
height = 5.6
is_student = False

print(name, age, height, is_student)
print(type(name), type(age), type(height), type(is_student))

age = "thirty"
print(age, type(age))

a, b, c = 1, 2, 3
print(a, b, c)

x = y = 100
print(x, y)

5. Output

text
Alice 30 5.6 False
<class 'str'> <class 'int'> <class 'float'> <class 'bool'>
thirty <class 'str'>
1 2 3
100 100

6. Key Takeaways

  • Variables are created by assignment (=); no explicit type declaration is needed.
  • Python is dynamically typed — a variable can be reassigned to a value of a different type.
  • Multiple assignment lets you assign several variables in one line: a, b, c = 1, 2, 3.
  • p = q = 100 binds both names to the same object.
  • Variable names must start with a letter or underscore, contain only letters/digits/underscores, and are case-sensitive.
  • PEP 8 recommends snake_case for variable names.

Practice what you learned

Was this page helpful?

Topics covered

#Python#PythonProgrammingStudyNotes#Programming#VariablesInPython#Variables#Syntax#Explanation#Example#StudyNotes#SkillVeris