Python Variables – Assign Multiple Values

1. What Does β€œAssign Multiple Values” Mean?

Normally, we assign one value to one variable.

Example:

a = 10

But Python also allows us to:

  • Assign many values to many variables

  • Assign one value to many variables

This is called assigning multiple values.

2. Assigning Many Values to Many Variables

You can give different values to different variables in one line.

Example

a, b, c = 10, 20, 30
print(a)
print(b)
print(c)

Output:

10
20
30

Here:

  • a gets 10

  • b gets 20

  • c gets 30

πŸ‘‰ The number of variables and values must be the same.

3. Assigning One Value to Many Variables

You can give the same value to many variables.

Example

x = y = z = 100
print(x)
print(y)
print(z)

Output:

100
100
100

All variables store the same value.

4. Assigning Values from a List

You can also assign values from a list.

Example

colors = ["red", "green", "blue"]
a, b, c = colors
print(a)
print(b)
print(c)

Output:

red
green
blue

5. Swapping Values Using Multiple Assignment

Python makes swapping values very easy.

Example

a = 5
b = 10
a, b = b, a

print(a)
print(b)

Output:

10
5

πŸ‘‰ No extra variable needed.

6. Common Beginner Mistakes

❌ Different Number of Values

a, b = 10, 20, 30

❌ Error because variables are less than values.

βœ” Correct Way

a, b, c = 10, 20, 30

❌ Forgetting Commas

a b c = 1 2 3

βœ” Correct:

a, b, c = 1, 2, 3

7. Simple Practice Examples

Example 1: Student Marks

math, science, english = 80, 75, 90
print(math)
print(science)
print(english)

Example 2: Same Value Assignment

count1 = count2 = count3 = 0
print(count1, count2, count3)

Example 3: Swap Two Numbers

x = 100
y = 200
x, y = y, x
print(x, y)

8. Summary (Assign Multiple Values)

βœ” Python allows multiple assignment
βœ” Many variables can get many values
βœ” One value can be shared by many variables
βœ” Swapping values is easy
βœ” Commas are very important

πŸ“˜ Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Python Data Types (easy)

  • Python Operators

  • Python Input from User

  • if–else statements

  • Practice questions + MCQs

Just tell me 😊

You may also like...