Sample questions
Question 1Easy
What is the output?
print(2 ** 3 ** 2)
- 64
- 36
- 18
- 512
Answer: D. 512
Explanation
is right-associative, so it is evaluated as 2 (3 2) = 2 9 = 512.
Step-by-step solution
- Groups from the right, so 3 2 is worked out first.
- 3 2 = 9, so the expression is 2 9.
- 2 9 = 512, the correct answer.
Why the other options are wrong
- A. 64 is (2 3) 2, which is the left-to-right reading. groups from the right.
- B. 36 is wrong; 2 9 is 512.
- C. 18 is wrong; 2 9 is 512.
Tip: In Python, is right-associative, so a b c means a (b c).
Question 2Easy
What is the output?
print(type(6 / 3).__name__)
- float
- double
- int
- number
Answer: A. float
Explanation
The / operator always performs true division and returns a float in Python 3, even when the result is whole (6 / 3 = 2.0).
Step-by-step solution
- The / operator always gives a float in Python 3, even when the result is whole.
- 6 / 3 is 2.0, and type() of that value is float.
- So the name printed is float, the correct answer.
Why the other options are wrong
- B. Double is not a Python type name.
- C. Int is wrong; / gives a float, while // gives an int for whole numbers.
- D. Number is not a type name; the class name is float.
Tip: / always returns a float. // returns an int when both operands are ints.
Question 3Easy
What is the output?
print(7 // 2, 7 % 2, -7 // 2)
- 3 1 -3
- 3 -1 -4
- 3.5 1 -3.5
- 3 1 -4
Answer: D. 3 1 -4
Explanation
// is floor division, so it rounds toward negative infinity: 7 // 2 = 3 and -7 // 2 = floor(-3.5) = -4.
7 % 2 = 1.
Step-by-step solution
- 7 // 2 is floor division, which gives 3.
- 7 % 2 is the remainder, which gives 1.
- -7 // 2 rounds down, so -3.5 goes to -4.
- The output is 3 1 -4, the correct answer.
Why the other options are wrong
- A. 3 1 -3 is wrong; // rounds down, so -7 // 2 is -4.
- B. 3 -1 -4 is wrong; 7 % 2 is 1, not -1.
- C. 3.5 1 -3.5 is wrong; // gives whole numbers.
Tip: // rounds down toward negative infinity, so -7 // 2 is -4, not -3.
Question 4Easy
Which of these built-in types is immutable?
- list
- set
- tuple
- dict
Answer: C. tuple
Explanation
Tuples cannot be changed after creation. Lists, dicts and sets can be modified in place.
Step-by-step solution
- A tuple cannot be changed after it is created.
- List, set and dict can all be changed in place.
- So the immutable type is tuple, the correct answer.
Why the other options are wrong
- A. List can be changed, for example with append.
- B. Set can be changed, for example with add and remove.
- D. Dict can be changed by adding or updating keys.
Tip: Immutable types include int, float, str, tuple and frozenset. Lists, sets and dicts are mutable.
Question 5Medium
What is the output?
print(bool("False"), bool(""), bool([0]))
- False False True
- True False False
- True False True
- False False False
Answer: C. True False True
Explanation
Any non-empty string is truthy (even "False"), the empty string is falsy, and a list with one element is truthy regardless of what the element is.
Step-by-step solution
- bool("False") is True, because any non-empty string is true, even one that spells False.
- bool("") is False, because the empty string is false.
- bool([0]) is True, because the list has one item, so it is not empty.
- The output is True False True, the correct answer.
Why the other options are wrong
- A. False False True is wrong; the string "False" is non-empty, so it is True.
- B. True False False is wrong; [0] is a non-empty list, so it is True.
- D. False False False is wrong; "False" and [0] are both non-empty, so both are True.
Tip: Falsy values are 0, 0.0, empty strings, empty containers, None and False. Most other values are truthy.
Question 6Medium
What is the output?
print(round(2.5), round(3.5))
- 2 3
- 3 3
- 3 4
- 2 4
Answer: D. 2 4
Explanation
round() uses round-half-to-even (banker's rounding): 2.5 rounds to 2 and 3.5 rounds to 4.
Step-by-step solution
- round() uses round-half-to-even, also called banker's rounding.
- 2.5 is halfway between 2 and 3, and the even choice is 2.
- 3.5 is halfway between 3 and 4, and the even choice is 4.
- The output is 2 4, the correct answer.
Why the other options are wrong
- A. 2 3 is wrong; 3.5 rounds to 4, the even neighbour.
- B. 3 3 is wrong; 2.5 rounds to 2, not 3.
- C. 3 4 is wrong; 2.5 rounds to 2, not 3.
Tip: Python's round() sends halves to the nearest even whole number.
Question 7Hard
What is the output?
a = [1, 2]
b = a
a += [3]
a = a + [4]
print(b)
- [1, 2, 4]
- [1, 2, 3]
- [1, 2]
- [1, 2, 3, 4]
Answer: B. [1, 2, 3]
Explanation
a += [3] extends the shared list in place, so b sees it. a = a + [4] builds a new list and rebinds only a, so b stays [1, 2, 3].
Step-by-step solution
- b = a makes b and a point to the same list.
- A += [3] extends that shared list in place, so b also shows [1, 2, 3].
- a = a + [4] builds a new list for a. Only a points to it, so b stays [1, 2, 3].
- The output is [1, 2, 3], the correct answer.
Why the other options are wrong
- A. [1, 2, 4] is wrong; b never sees the 4, because a was rebound to a new list.
- C. [1, 2] is wrong; += changed the shared list to include 3.
- D. [1, 2, 3, 4] is wrong; a + [4] makes a new list, and b does not point to it.
Tip: += changes a list in place, but + builds a new list. Other names that point to the old list do not see the new one.
Practise all 7 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →