Python Quiz

Python is known for readable syntax and is used in web development, automation, data science and AI. The questions cover data types, control flow, functions, lists, dictionaries, strings and basic object-oriented ideas.

What this quiz covers

Study tip: Type the code from each question into a Python shell; predicting the output before you run it is the fastest way to improve.

Questions, answers and explanations

1. Who developed Python?

  1. James Gosling
  2. Guido van Rossum
  3. Dennis Ritchie
  4. Bjarne Stroustrup

Answer: Guido van Rossum

Python was created by Guido van Rossum and first released in 1991.

2. Python is a ____ programming language.

  1. Compiled
  2. Interpreted
  3. Assembly
  4. Machine

Answer: Interpreted

Python is an interpreted high-level programming language.

3. Which file extension is used for Python files?

  1. .java
  2. .py
  3. .cpp
  4. .js

Answer: .py

Python source files use the .py extension.

4. Which function is used to display output in Python?

  1. echo()
  2. print()
  3. display()
  4. printf()

Answer: print()

The print() function displays output on the screen.

5. Which function is used to get user input in Python?

  1. scan()
  2. cin()
  3. input()
  4. read()

Answer: input()

The input() function accepts user input.

6. Which keyword is used to define a function in Python?

  1. function
  2. def
  3. func
  4. define

Answer: def

Functions in Python are created using the def keyword.

7. Which symbol is used for comments in Python?

  1. //
  2. #
  3. /* */
  4. --

Answer: #

The # symbol is used for single-line comments.

8. Which data type stores True or False values?

  1. int
  2. bool
  3. string
  4. float

Answer: bool

The bool data type stores Boolean values.

9. Which keyword is used for conditional statements?

  1. if
  2. when
  3. switch
  4. select

Answer: if

The if statement is used to make decisions in Python.

10. Which loop is used to iterate over a sequence?

  1. for
  2. repeat
  3. loop
  4. iterate

Answer: for

The for loop is commonly used to iterate through lists, tuples, strings, and other sequences.

11. Which data type is used to store multiple items in order?

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

Answer: list

A list stores multiple ordered and mutable items.

12. Which keyword is used to create a class in Python?

  1. class
  2. object
  3. struct
  4. define

Answer: class

The class keyword is used to define a class.

13. Which operator is used for exponentiation in Python?

  1. ^
  2. **
  3. *
  4. //

Answer: **

The ** operator is used to calculate powers.

14. Which function returns the length of a list or string?

  1. size()
  2. count()
  3. len()
  4. length()

Answer: len()

The len() function returns the number of items.

15. Which keyword is used to import a module?

  1. include
  2. import
  3. using
  4. require

Answer: import

Modules are imported using the import keyword.

16. Which Python collection stores key-value pairs?

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

Answer: dictionary

A dictionary stores data in key-value pairs.

17. Which statement is used to handle exceptions?

  1. try-except
  2. catch
  3. throw
  4. error

Answer: try-except

Python uses try and except blocks for exception handling.

18. Which keyword is used to create an anonymous function?

  1. lambda
  2. anonymous
  3. func
  4. inline

Answer: lambda

Lambda creates small anonymous functions.

19. Which loop continues until a condition becomes false?

  1. for
  2. while
  3. repeat
  4. loop

Answer: while

The while loop executes as long as its condition is true.

20. Which of the following is a major advantage of Python?

  1. Easy to Learn
  2. Large Standard Library
  3. Cross Platform
  4. All of the above

Answer: All of the above

Python is easy to learn, cross-platform, and has a huge standard library.

Take the timed quiz