How to Swap Two Numbers in Python (With and Without a Function)
To swap two numbers in Python, use tuple unpacking: a, b = b, a. It is one line, works for any type (integers, floats, strings, list items) and needs no temporary variable. This guide shows that and the classic alternatives (a temporary variable, arithmetic and XOR), explains how swapping works inside a function, and includes … Read more >>









