In Python, we can assign a single value to more than one variable simultaneously.
For example:
count=salary=a=b=0
The above statement is assigning 0 to four variables. We can also assign different values to multiple variables simultaneously, as shown below:
Salary, x,y=12000, 90, “Student”
Here, variable Salary and x are integers, and y is a string. Salary is assigned a value of 12000, x is assigned 90, and y is assigned “Student.”
Here we are giving an example for assigning a single value to three variables a, b and c
a=b=c=90 print(a," ",b," ",c)
Output:
90 90 90
We are now giving another example of assigning different values to different variables.
roll,salary,age=23,15000,34 print("Roll=",roll) print("Salary=",salary) print("Age=",age)
Output:
Roll=23 Salary=15000 Age=34
Leave a comment