livepython.net

24. Python Program to Swap Two Variables Without a Temporary Variable

MediumHow they work

Overview

Swap values between variables efficiently.

Problem Statement

Swap values of two variables without a temporary variable.

Constraints:

  • Initialize a = 5 and b = 10
  • After swapping, print both values
  • Do not use any temporary variable

Input

  • No input required

Output

10 5

Learn this firstChapter 4 · How Python Variables Work: Reassign, Swap and More
solution.py
# write your code here

EXPECTED OUTPUT

110 5

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.