Python Program to Swap two Numbers
We can do multiple assignments with comma operator. Syntax as follows,
x,y = 10,20 print(x) print(y)
In this example, you will learn to swap two variables by using comma operator.
a=10 b=20 print("Before Swaping : ") print("a = ",a) print("b = ",b) a,b=b,a print("After Swaping : ") print("a = ",a) print("b = ",b)
Before Swaping : a = 10 b = 20 After Swaping : a = 20 b = 10