+1 vote
in Programming Languages by (75.0k points)
Can the values of two variables be swapped using a single line of code in Python?

1 Answer

+2 votes
by (353k points)
selected by
 
Best answer

It's very simple to swap the values of two variables using a single line of code in Python.

Here is an example:

>>> a=12
>>> b=15
>>> a,b=b,a
>>> a
15
>>> b
12
>>>


...