Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

swapping two numbers in pythin

x=int(input("Enter x:"))
y=int(input("Enter y:"))

# Method 1
x,y=y,x
print(x,y)

# Method 2
t=x
x=y
y=t
print(x,y)

# Method 3
x=x+y
y=x-y
x=x-y
print(x,y)

# Method 4
x=x^y
y=x^y
x=x^y
print(x,y)

# Method 5
x=x*y
y=x/y
x=x/y
print(x,y)
 
PREVIOUS NEXT
Tagged: #swapping #numbers #pythin
ADD COMMENT
Topic
Name
1+3 =