Skip to content

Commit eddc02c

Browse files
committed
added swaping variables
1 parent 0e617cb commit eddc02c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

swaping variables.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
a=5
2+
b=6
3+
# by using an extra variable
4+
temp=a
5+
a=b
6+
b=temp
7+
print (a)
8+
print (b)
9+
10+
# other method; btw wasting an extra bit
11+
a=a+b
12+
b=a-b
13+
a=a-b
14+
15+
#by XOR method
16+
17+
a=a^b
18+
b=a^b
19+
a=a^b
20+
21+
# (only in python)
22+
a,b=b,a
23+
24+
#Code by Steavo Babu

0 commit comments

Comments
 (0)