Lists & Tuples · Question 7 · Easy
Two variables are exchanged using tuple packing and unpacking. What is printed?
a, b = 5, 9
a, b = b, a
print(a, b)
- 5 9
- 9 9
- 5 5
- 9 5
Answer and explanation
Answer: D. 9 5
Explanation: The right side b, a is packed into the tuple (9, 5) before any assignment happens. It is then unpacked into a and b, so the values are swapped.
Previous: An element of a tuple is assigned a new value. What happens? · Next: The same list goes through sorted() and then sort(). What does this print?
Practise lists & tuples
Try a fresh set of lists & tuples questions with an explanation after every answer, free and without signing up: Lists & Tuples practice. Or sit a full placement mock test.
More lists & tuples questions
- Three facts about a tuple of scores are printed. What is the output?
- A list is appended to another list. What length does this print?
- An element of a tuple is assigned a new value. What happens?
- The same list goes through sorted() and then sort(). What does this print?
- One name is a slice copy of the list a and another is a plain assignment. What…
- remove() and pop() are used on a queue of token numbers. What does this print?
- A starred name is used while unpacking a list. What is printed?
- For the tuple t = (1, 2, 3), which of these operations is NOT allowed?
- A marks table is stored as a list of rows. What does this print?
- Kavya has a list a and wants b to be a separate list with the same items, so…
More python practice
Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge