Chapters
Python114 chapters

Exercises

Multiple Assignment

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Swap the values of left and right in a single line, without a temporary variable.

Python
left = "A"
right = "B"
# swap them here
print(left, right)
Exercise 2

Unpack the point tuple into x and y, then print their sum.

Python
point = (4, 9)
# unpack into x and y
print(x + y)
Exercise 3

Use a starred name so first holds 10 and rest holds the other three numbers.

Python
numbers = [10, 20, 30, 40]
# assign first and rest
print(first)
print(rest)