A Program to Swap Two Variables

In this example, we are giving a program to swap two variables.


Program to swap two variables:

  1. # Swap two variable
  2. a = float(input('Enter the value of a: '))
  3. b = float(input('Enter the value of b: '))
  4. temp = a
  5. a = b
  6. b = temp
  7. print('The value of a after swapping: {}'.format(a))
  8. print('The value of b after swapping: {}'.format(b))

Output:

Enter the value of a: 5
Enter the value of b: 7
The value of a after swapping: 7.0
The value of b after swapping: 5.0