Important Notice:

Swap Two Variable

Swap Two Variable

3 views 1 min read

Swap Two Variables in Python (दो Variables की Values आपस में बदलना) :-

Example: -

Before Swapping:

a = 10
b = 20
 
After Swapping:
a = 20
b = 10
 
Program -
# Input
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

# Before Swapping
print("Before Swapping:")
print("a =", a)
print("b =", b)

# Swap using temporary variable
temp = a
a = b
b = temp

# After Swapping
print("After Swapping:")
print("a =", a)
print("b =", b)
 
Output-
 
Enter first number: 10
Enter second number: 20

Before Swapping:
a = 10
b = 20

After Swapping:
a = 20
b = 10
 

Related Notes