Python Swap Variables in One Line

Swap two variables WITHOUT a temp variable. 🔄 a = 5 b = 10 How do you swap them in Python in ONE line? 🐍 A) a = b; b = a B) a, b = b, a C) swap(a, b) Pythonic magic! ✨ 👇 **Comment A, B, or C!** Show off your Python skills! 🐍 #Python #Coding #Tips #Tricks #Developer

  • No alternative text description for this image

I think C is right cause we have to give swipe command for swiping

Like
Reply

B. It's a direct command a=5 b=10 a,b=b,a Print(a,b) Output:10 5

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories