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 collects typed user input?
  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

In Python, what does append() do to a list?
  1. Adds an item to the end
  2. Removes the last item
  3. Sorts the list
  4. Prints the list

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 only

Question 13

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

Question 14

In Python, when does else run?
  1. When the condition is false
  2. When the condition is true
  3. At the start of a program
  4. Only inside loops

Question 15

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

Question 16

In Python, what does int("5") return?
  1. 5
  2. "5"
  3. 0
  4. Always an error

Question 17

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

Question 18

In Python functions, what does return do?
  1. Sends a value back from the function
  2. Displays a value on the screen
  3. Repeats the function automatically
  4. Stores a value as 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 keyword imports a module in Python?
  1. import
  2. include
  3. load
  4. module

Question 22

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

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