Skip to content

Commit

Permalink
Update swap.py
Browse files Browse the repository at this point in the history
Streamlined the swapping of the values to avoid the use of temporary variables and using python built-in function
  • Loading branch information
Piombacciaio committed Mar 14, 2023
1 parent 8cc8686 commit f21dc16
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
# x = input('Enter value of x: ')
# y = input('Enter value of y: ')

# create a temporary variable and swap the values
temp = x
x = y
y = temp
# Swap the values of x and y without the use of any temporary value
x, y = y, x

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

0 comments on commit f21dc16

Please sign in to comment.