Python – swap variable without adding new variable

Bagaimana kah caranya swap variable (int) tanpa ada bantuan variable baru.

begini caranya guys:

 



print('Enter x:')
x = int(input())

print('Enter y:')
y = int(input())

print("X:"+ str(x) +" Y:"+ str(y))

x = x + y
y = x - y
x = x - y

print("X:"+ str(x) +" Y:"+ str(y))

Git: https://github.com/akrisnanda/py-swap-without-adding-new-var

 

terimakasih

Related Posts