Python 3 – Assign Many/ Single Values to Multiple Variables

In Python, we can assign multiple values to the multiple variables at the same time using commas. This saves us a lot of time when assigning a large number of variables.

How to Assign Multiple Variable with Multiple Values in One Line in Python?

You can assign multiple(or same) data types of values to a comma-separated variable list:

a,b,c,d,e = "Apple","Boat",13.55,True,123
print(a)
print(b)
print(c)
print(d)
print(e)

#OUTPUT#

Apple
Boat
13.55
True
123

 

How to Assign Multiple Variable with Single Value in Python?

To assign a single value to multiple variables is done by adding = sign between them:

a = b = c = d = e = "Apple"
print(a)
print(b)
print(c)
print(d)
print(e)

#OUTPUT#


Apple
Apple
Apple
Apple
Apple

Leave a Reply

Your email address will not be published. Required fields are marked *