Python questions

By Interwoven Maths

Python question collection

Review Python questions for Computer Science, with correct answers shown and coverage across variables and data types; selection and iteration; functions and parameters.

Back to Python practice Back to Computer Science

Question 1

Which function displays text in Python?
  1. print()
  2. input()
  3. len()
  4. range()

Question 2

In Python, which function reads text typed by the user?
  1. input()
  2. print()
  3. int()
  4. str()

Question 3

Which symbol starts a comment in Python?
  1. #
  2. //
  3. /*
  4. @

Question 4

In Python, which symbol assigns a value to a variable?
  1. =
  2. ==
  3. :
  4. +

Question 5

In Python, which operator checks if two values are equal?
  1. ==
  2. =
  3. !=
  4. >=

Question 6

Which Python type stores whole numbers?
  1. int
  2. str
  3. float
  4. bool

Question 7

Which Python type stores text?
  1. str
  2. int
  3. float
  4. bool

Question 8

In Python, what is len("cat")?
  1. 3
  2. 2
  3. 4
  4. 0

Question 9

In Python, what is the first index in a list?
  1. 0
  2. 1
  3. -1
  4. 2

Question 10

After items = [1, 2]; items.append(3), what is items?
  1. [1, 2, 3]
  2. [3, 1, 2]
  3. [1, 2]
  4. [1, 2, [3]]

Question 11

Which keyword starts a loop that repeats a set number of times?
  1. for
  2. while
  3. if
  4. def

Question 12

In Python, what values come from range(3)?
  1. 0, 1, 2
  2. 1, 2, 3
  3. 0, 1, 2, 3
  4. 3

Question 13

In Python, which keyword starts a decision statement?
  1. if
  2. for
  3. import
  4. return

Question 14

An if condition is false. Which branch runs?
  1. else
  2. if
  3. for
  4. while

Question 15

In Python, True and False are values of which type?
  1. bool
  2. int
  3. str
  4. list

Question 16

What does int("5") return?
  1. 5
  2. "5"
  3. 5.0
  4. An error

Question 17

In Python, which keyword defines a function?
  1. def
  2. function
  3. proc
  4. return

Question 18

What does return do in a Python function?
  1. Sends a value to the caller
  2. Displays a value on screen
  3. Restarts the function
  4. Creates a global variable

Question 19

In Python, what does "cat".upper() return?
  1. "CAT"
  2. "cat"
  3. "Cat"
  4. An error

Question 20

Which Python keyword starts a condition-controlled loop?
  1. while
  2. for
  3. if
  4. print

Question 21

Which Python keyword loads a module?
  1. import
  2. include
  3. load
  4. module

Question 22

What does [10, 20, 30][1] return?
  1. 20
  2. 10
  3. 30
  4. 1

Question 23

What does sum([2, 3]) return?
  1. 5
  2. 6
  3. 23
  4. 2

Question 24

When is A and B true?
  1. A and B are both true
  2. Only A is true
  3. Only B is true
  4. A and B are both false

Question 25

Which collection uses zero-based indexes and can be changed?
  1. list
  2. tuple
  3. set
  4. dict

Question 26

What does "cat"[1:] return?
  1. "at"
  2. "c"
  3. "ca"
  4. "cat"

Question 27

Which operator means “not equal to” in Python?
  1. !=
  2. =
  3. ==
  4. <=

Question 28

What supplies a value to a function parameter?
  1. An argument
  2. A return value
  3. A condition
  4. An index

Question 29

Which type does input() return?
  1. str
  2. int
  3. bool
  4. list

Question 30

What does indentation show in Python?
  1. Block structure
  2. Data type
  3. Operator precedence
  4. Variable scope

About this topic

Review Python questions for Computer Science, with correct answers shown and coverage across variables and data types; selection and iteration; functions and parameters.

This topic covers

Example question types