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
- Data types and operators
- Conditions and loops
- Lists, tuples and dictionaries
- Functions and modules
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?
- James Gosling
- Guido van Rossum
- Dennis Ritchie
- Bjarne Stroustrup
Answer: Guido van Rossum
Python was created by Guido van Rossum and first released in 1991.
2. Python is a ____ programming language.
- Compiled
- Interpreted
- Assembly
- Machine
Answer: Interpreted
Python is an interpreted high-level programming language.
3. Which file extension is used for Python files?
- .java
- .py
- .cpp
- .js
Answer: .py
Python source files use the .py extension.
4. Which function is used to display output in Python?
- echo()
- print()
- display()
- printf()
Answer: print()
The print() function displays output on the screen.
5. Which function is used to get user input in Python?
- scan()
- cin()
- input()
- read()
Answer: input()
The input() function accepts user input.
6. Which keyword is used to define a function in Python?
- function
- def
- func
- define
Answer: def
Functions in Python are created using the def keyword.
7. Which symbol is used for comments in Python?
- //
- #
- /* */
- --
Answer: #
The # symbol is used for single-line comments.
8. Which data type stores True or False values?
- int
- bool
- string
- float
Answer: bool
The bool data type stores Boolean values.
9. Which keyword is used for conditional statements?
- if
- when
- switch
- select
Answer: if
The if statement is used to make decisions in Python.
10. Which loop is used to iterate over a sequence?
- for
- repeat
- loop
- 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?
- list
- set
- dictionary
- tuple
Answer: list
A list stores multiple ordered and mutable items.
12. Which keyword is used to create a class in Python?
- class
- object
- struct
- define
Answer: class
The class keyword is used to define a class.
13. Which operator is used for exponentiation in Python?
- ^
- **
- *
- //
Answer: **
The ** operator is used to calculate powers.
14. Which function returns the length of a list or string?
- size()
- count()
- len()
- length()
Answer: len()
The len() function returns the number of items.
15. Which keyword is used to import a module?
- include
- import
- using
- require
Answer: import
Modules are imported using the import keyword.
16. Which Python collection stores key-value pairs?
- list
- tuple
- dictionary
- set
Answer: dictionary
A dictionary stores data in key-value pairs.
17. Which statement is used to handle exceptions?
- try-except
- catch
- throw
- error
Answer: try-except
Python uses try and except blocks for exception handling.
18. Which keyword is used to create an anonymous function?
- lambda
- anonymous
- func
- inline
Answer: lambda
Lambda creates small anonymous functions.
19. Which loop continues until a condition becomes false?
- for
- while
- repeat
- 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?
- Easy to Learn
- Large Standard Library
- Cross Platform
- All of the above
Answer: All of the above
Python is easy to learn, cross-platform, and has a huge standard library.