Skip to main content

Command Palette

Search for a command to run...

Multiple Assignment

Allows us to assign multiple variables at the same time in one line of code.

Updated
•1 min read•View as Markdown

Example For Standard Assignments

Name = "Bro"
Age = 40
Attractive = True

print(Name)
print(Age)
print(Attractive)

Output:

Bro

40

True

Multiple Assignments Example

Name, Age, Attractive = "Bro", 21, True
print(Name)
print(Age)
print(Attractive)

Output:

Output = Bro

Output = 21

Output = True

Standard Example With the same value in every Variable

Mike = 35
Donald = 35
Shyam = 35
Kiran = 35

print(Mike)
print(Donald)
print(Shyam)
print(Kiran)

Output:

35

35

35

35

IN Multiple assignments we can above in a very easy way. Like Below :

Mike = Donald = Shyam = Kiran = 35

print(Mike)
print(Donald)
print(Shyam)
print(Kiran)

Output:

Output = 35

Output = 35

Output = 35

Output = 35

Below Output will show only the Values of the Variable. [To Combine the Values And Variable we can use the (,) Separate between the data Types (Str and Int)]

Mike = Donald = Shyam = Kiran = 35
print("Mike : ", Mike, "Donald : ", Donald,
      "Shyam : ", Shyam, "Mike : ", Kiran)

OutPut :

Mike : 35 Donald : 35 Shyam : 35 Mike : 35