+ 2

Is there any way shorter than this? To swap values in more than 2 variables (mine is for 2 variables only)

https://code.sololearn.com/cZHglsn7C6Sl/?ref=app

6th Oct 2018, 2:13 PM
partha
partha - avatar
4 Respuestas
+ 5
in Python you can just do: x = 1 y = 2 x, y = y, x
6th Oct 2018, 2:20 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
thanks Ulisses Cruz it even worked for more than 2 variables
6th Oct 2018, 2:30 PM
partha
partha - avatar
+ 2
Just a tip, search for performance tips on Python. This example Ulisses gave you is one of those tips. You may learn a lot of things reading it
6th Oct 2018, 3:44 PM
Alexander Santos
Alexander Santos - avatar
0
thanks Alexander Santos it's really useful 😀
6th Oct 2018, 3:55 PM
partha
partha - avatar