swapping in python
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)
swapping in python
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)
python swap numbers
x, y = 10, 20
print(x, y) # 10 20
x, y = y, x
print(x, y) # 20 10
python swap numbers
# Swap without using any temp variable
x = 66
y = 77
print("Original: ", x,y)
x = x - y
y = x + y
x = y - x
print("Swapped 1st time: ", x,y)
x = x + y
y = x - y
x = x - y
print("Swapped 2nd time: ", x,y)
# Output:
# Original: 66 77
# Swapped 1st time: 77 66
# Swapped 2nd time: 66 77
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us