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

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 program for swapping position of two numbers

#program to swap indexes of present to succedinng one or viceversa
list=eval(input("enter a list"))
print(list)
a=len(list)
if a%2!=0:
    a=a-1
for i in range(0,a,2):
    list[i],list[i+1]=list[i+1],list[i]
print("swapped position and the list is",list)
Comment

python swap two numbers

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

python swap two numbers

pos1, pos2  = 1, 3
Comment

PREVIOUS NEXT
Code Example
Python :: pandas cheat sheet pdf 
Python :: dropout keras 
Python :: numpy stack arrays vertically 
Python :: E: Unable to locate package python-gobject 
Python :: raise exception in python 
Python :: numpy is not nan 
Python :: validate ip address python 
Python :: script python to download videio from any website 
Python :: python add item multidimensional list 
Python :: how to clear a list in python 
Python :: python list count() 
Python :: pandas take first n rows 
Python :: flask-callable 
Python :: Chi-Squared test in python 
Python :: openpyxl full tutorial 
Python :: how to find last index of list in python 
Python :: how to open a website using python 
Python :: tower of hanoi python 
Python :: html.unescape python 
Python :: python timestamp to yyyy-mm-dd 
Python :: np one hot encoding 
Python :: python sum array 
Python :: how to use global variable in python 
Python :: how to take input for list in python 
Python :: django logout page 
Python :: django login code 
Python :: send telegram bot message python 
Python :: non-default argument follows default argument 
Python :: pandas select rows by multiple conditions 
Python :: leap year python 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =