Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — Variables & Assignment Statements

Lesson 8 of 50 in the free Python Programming notes on Siksha Sarovar, written by Rohit Jangra.

Variables and Assignment Statements

A variable is a named reference to a value stored in memory. Python variables do not need explicit type declaration — the type is determined at runtime (dynamic typing).

age = 20            # int
name = "Aditi"       # str
gpa = 8.7            # float
is_pass = True       # bool

Assignment Statement Forms

1. Simple assignment

x = 10

2. Multiple assignment (same value to many variables)

a = b = c = 100
print(a, b, c)   # 100 100 100

3. Multiple assignment (different values, one line)

x, y, z = 1, 2, 3
print(x, y, z)   # 1 2 3

4. Swapping values without a temp variable

a, b = 5, 10
a, b = b, a
print(a, b)      # 10 5

5. Augmented (compound) assignment

x = 10
x += 5    # x = x + 5  -> 15
x -= 2    # x = x - 2  -> 13
x *= 3    # x = x * 3  -> 39
x /= 2    # x = x / 2  -> 19.5

Rules

  • Python variables are references to objects — assigning a new value rebinds the name; it does not overwrite memory in place for immutable types.
  • type() can be used to inspect a variable's current type at any point.
  • Variables can be re-declared with a different type at any time (dynamic typing).
value = 100
print(type(value))     # <class 'int'>
value = "one hundred"
print(type(value))     # <class 'str'>

id() — memory reference

a = 10
b = 10
print(id(a) == id(b))  # True — small ints are cached/interned by CPython