Skip to content

Commit f21dc16

Browse files
committed
Update swap.py
Streamlined the swapping of the values to avoid the use of temporary variables and using python built-in function
1 parent 8cc8686 commit f21dc16

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

swap.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
# x = input('Enter value of x: ')
66
# y = input('Enter value of y: ')
77

8-
# create a temporary variable and swap the values
9-
temp = x
10-
x = y
11-
y = temp
8+
# Swap the values of x and y without the use of any temporary value
9+
x, y = y, x
1210

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

0 commit comments

Comments
 (0)