Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)
In this way, a friend of mine asked how my python programming was coming; I said I was learning a ton and that it was tagging along pleasantly. At that point my companion, a math-stiff neck, asks me:

"Would you be able to swap the value of 2 factors without utilizing a third variable as a temporary placeholder?"

1 Answer

0 votes
by (26.4k points)

The canonical method to swap two factors/variables in Python is 

a, b = b, a

Kindly note that this is substantial whatever the "type" of a or b is (numeric, string, tuple, object, ...). Obviously, it works as well if the two variables reference estimations of various types.

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

To know more about this you can have a look at the following video tutorial:-

Related questions

Browse Categories

...