What do you understand by multiple assignments?

1.0K    Asked by SherlyMontejano in Data Science , Asked on Jan 9, 2020
Answered by Nitin Solanki

 Multiple assignments mean assigning multiple or same values to multiple variables at the same. In python, you can assign values to multiple variables in one go. For example-

a = b = c = d = 20

If you run above code in python variable a, b, c, d will be assigned value 20. Here an integer object is created with the value 20 and all four variables are assigned to the same memory.


See one more example below:

a, b, c, d = 1, 2, 3, "jankbask"

In the above example, four objects are created out of which three are integer and one is a string and all the integer objects are assigned to variables a, b and c respectively and string object is assigned to variable d.



Your Answer

Interviews

Parent Categories