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...