Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

python swap two elements

a = 1
b = 2
# Swap a and b
a, b = b, a
Comment

swapping of two numbers in python

a,b=5,6
print(a,b)  
a=a+b  
b=a-b   
a=a-b
print(a,b)
Comment

python swap two numbers

def swap(a, b):
  a = a + b
  b = a - b
  a = a - b
  return a, b
Comment

Swap 2 items of a list in python

in python below is how you swap 2 elements of list
            x[i+1],x[i]=x[i],x[i+1]
Don't use function swap(user defined or pre-defined)
Comment

python swap two numbers

pos1, pos2  = 1, 3
Comment

PREVIOUS NEXT
Code Example
Python :: colab add library 
Python :: python export multiple dataframes to excel 
Python :: python copy dataframe 
Python :: pandas list to df 
Python :: How to Create Caesar Cipher Using Python 
Python :: invert a dictionary python 
Python :: python gzip file 
Python :: import matplotlib plt 
Python :: change tensor type pytorch 
Python :: if django 
Python :: taking string input from user in python with try except 
Python :: sorting by second element 
Python :: 2d array pytho 
Python :: generics python 
Python :: python horizontal line 
Python :: python rsa 
Python :: python catch multiple exceptions 
Python :: python list of integers 
Python :: Python DateTime add days to DateTime object 
Python :: find how many of each columns value pd 
Python :: with urllib.request.urlopen("https:// 
Python :: R write dataframe to file 
Python :: kaggle vs colab 
Python :: np.rand.randint 
Python :: python absolute value 
Python :: python 64 bit 
Python :: python append to csv on new line 
Python :: how to get decimal part of a double in python 
Python :: plotly line plot 
Python :: flatten numpy array 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =