Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to swap numbers in python mathematically

def swap_by_temp_var(num1,num2):
    temp = num1
    num1 = num2
    num2 = temp
    return num1, num2
def swap_by_mathamatically(num1,num2):
    num1 = num1 + num2
    num2 = num1-num2
    num1 = num1-num2
    return num1, num2
print(swap_by_temp_var(100,80))
print(swap_by_mathamatically(100,80))
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #swap #numbers #python #mathematically
ADD COMMENT
Topic
Name
4+5 =