Basics & Data Types Questions with Answers

7 practice questions on Basics & Data Types (Python) with answers and step-by-step solutions. Try 7 samples below, then practise all 7 free in the AptiNest app.

Sample questions

Question 1Easy

What is the output?

print(2 ** 3 ** 2)
  1. 64
  2. 36
  3. 18
  4. 512

Answer: D. 512

Explanation

is right-associative, so it is evaluated as 2 (3 2) = 2 9 = 512.

Step-by-step solution

  1. Groups from the right, so 3 2 is worked out first.
  2. 3 2 = 9, so the expression is 2 9.
  3. 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__)
  1. float
  2. double
  3. int
  4. 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

  1. The / operator always gives a float in Python 3, even when the result is whole.
  2. 6 / 3 is 2.0, and type() of that value is float.
  3. 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)
  1. 3 1 -3
  2. 3 -1 -4
  3. 3.5 1 -3.5
  4. 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

  1. 7 // 2 is floor division, which gives 3.
  2. 7 % 2 is the remainder, which gives 1.
  3. -7 // 2 rounds down, so -3.5 goes to -4.
  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?

  1. list
  2. set
  3. tuple
  4. dict

Answer: C. tuple

Explanation

Tuples cannot be changed after creation. Lists, dicts and sets can be modified in place.

Step-by-step solution

  1. A tuple cannot be changed after it is created.
  2. List, set and dict can all be changed in place.
  3. 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]))
  1. False False True
  2. True False False
  3. True False True
  4. 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

  1. bool("False") is True, because any non-empty string is true, even one that spells False.
  2. bool("") is False, because the empty string is false.
  3. bool([0]) is True, because the list has one item, so it is not empty.
  4. 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))
  1. 2 3
  2. 3 3
  3. 3 4
  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

  1. round() uses round-half-to-even, also called banker's rounding.
  2. 2.5 is halfway between 2 and 3, and the even choice is 2.
  3. 3.5 is halfway between 3 and 4, and the even choice is 4.
  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. [1, 2, 4]
  2. [1, 2, 3]
  3. [1, 2]
  4. [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

  1. b = a makes b and a point to the same list.
  2. A += [3] extends that shared list in place, so b also shows [1, 2, 3].
  3. a = a + [4] builds a new list for a. Only a points to it, so b stays [1, 2, 3].
  4. 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 →

Related topics

See all Python topics · All topics