Python Program to Swap two Variables - Python for Data Analytics

Python Programs | Python Tricks | Solution for problems | Data Cleaning | Data Science

Python Program to Swap two Variables

Source Code:


# Python program to swap two variables

x = 5
y = 10

# create a temporary variable and swap the values
temp = x
x = y
y = temp

print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))


Output:

Screen-shot

No comments:

Post a Comment