Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
In python in order to swap variables you can use unpack feature:

>>> a, b = 1, 2
>>> a, b = b, a
>>> a, b
(2, 1)

This is a nice way to swap variables without using a third variable.

#python #swap #swap_variables
In-place value swapping

# Let's say we want to swap
# the values of a and b...
a = 23
b = 42

# The "classic" way to do it
# with a temporary variable:
tmp = a
a = b
b = tmp

# Python also lets us
# use this short-hand:
a, b = b, a

#python #swap #tricks