Getting your questions ready
Getting your questions ready
Beat the crowd
10 questions No timer
Test your Python programming knowledge with our comprehensive free 96-question trivia quiz with answers. Whether you're a beginner learning the basics or an intermediate developer, this quiz covers essential Python concepts, syntax, and best practices. See how well you really know Python!
30 of 96 questions with answers and explanations. Play the quiz
Q 01What is the name of the creator of the Python programming language?
Guido van Rossum
Python was created by Guido van Rossum, who first released it in 1991.
Q 02Which keyword ends a function call and hands a value back to the caller?
`return`
`return` ends the function and passes its value to the caller; a function that falls off the end without one returns None, and `exit` is not a keyword at all.
Q 03In what year was the first public version of Python released?
1991
1991's release on February 20 came from Guido van Rossum, who had started the project as a Christmas hobby in 1989.
Q 04What is the official style guide for Python code, promoting readability and consistency?
PEP 8
PEP 8, the 'Style Guide for Python Code' written by Guido van Rossum and Barry Warsaw in 2001, sets conventions such as a 79-character line limit and snake_case function names.
Q 05How does Python define code blocks, unlike languages that use curly braces?
Indentation
Python's design philosophy emphasizes code readability with the use of significant indentation to define code blocks.
Q 06What is the standard package installer for Python called?
pip
pip's name is a recursive acronym, 'pip installs packages'; npm, gem and apt serve JavaScript, Ruby and Debian respectively.
Q 07Which Python data type is mutable?
List
List elements can be modified after creation, while tuples, strings and integers are immutable, which is why only the latter can be dictionary keys.
Q 08In CPython, what does the Global Interpreter Lock (GIL) actually do?
Lets only one thread run Python bytecode at a time
The GIL lets only one thread run Python bytecode at a time, so threads help with I/O-bound waiting but not CPU-bound work; Python 3.13 added an experimental build that can disable it.
Q 09Which OOP principle bundles data and the methods that operate on it into a single class?
Encapsulation
Encapsulation bundles attributes and methods into one class and hides the object's internal state; Python signals 'private' only by convention, with a leading underscore.
Q 10Which category do `int`, `float`, and `complex` data types belong to in Python?
Numeric
Numeric types are the three: integers, floats and complex numbers; booleans are technically a subtype of integers, and the standard library adds Fraction and Decimal.
Q 11Which 'fully loaded' Python web framework handles authentication, admin and RSS out of the box?
Django
Django's own tagline is 'the web framework for perfectionists with deadlines'; Flask and FastAPI are deliberately slimmer micro-frameworks.
Q 12What character is used to denote a single-line comment in Python?
#
In Python, the hash symbol (`#`) is used to indicate a single-line comment; any text following it on the same line is ignored by the interpreter.
Q 13Which aphorism is NOT in 'The Zen of Python' (PEP 20)?
There's more than one way to do it.
Perl's motto is 'There's more than one way to do it.' The Zen says the opposite: 'There should be one-- and preferably only one --obvious way to do it.'
Q 21Which keyword is used in Python to create a generator function?
yield
Generator functions in Python use the 'yield' keyword instead of 'return' to produce a sequence of values one at a time, pausing execution between each, making them memory efficient.
Q 22What is the purpose of the `super()` function in Python?
To reach a parent class's methods from a subclass
The `super()` function returns a proxy object that allows you to access methods and attributes of a parent or sibling class from within a child class, which is particularly useful in inheritance.
Q 23What does a Python decorator do?
Q 14Which Python library is foundational for numerical computing with multi-dimensional arrays?
NumPy
NumPy (Numerical Python) is the foundational package for numerical computing in Python, providing support for multidimensional arrays and matrices.
Q 15In what year did Python 2 officially reach End-of-Life?
2020
2020's sunset was followed by a final 2.7.18 release in April to wrap up fixes already merged; Python 3 had been out since 2008.
Q 16What keyword is used to define a function in Python?
def
The 'def' keyword, short for 'define', is used to declare a function in Python, followed by the function name, parentheses for parameters, and a colon.
Q 17What will be the output of the following Python expression: `5 + 2 * 3`?
11
Python follows standard operator precedence rules, where multiplication (*) is performed before addition (+), so `2 * 3` evaluates to `6`, and `5 + 6` equals `11`.
Q 18Which of the following is NOT a valid Python identifier?
2nd_total
`2nd_total` is invalid because an identifier cannot begin with a digit; names must start with a letter or underscore, so my_total, _private_total and totalCount are all legal.
Q 19To open a file named 'example.txt' for writing, which mode would you use in the `open()` function?
'w'
'w' truncates an existing file and creates a new one if none exists; 'a' appends, 'r' reads, and 'x' creates only if the file does not already exist.
Q 20What does a Python class's `__init__` method do?
To initialize object attributes
The `__init__` method is a special method, often called a constructor, that is automatically invoked when a new object (instance) of a class is created, allowing for the initialization of its attributes.
Wraps a function to extend or alter its behaviour
Applied with the @wrapper syntax, a decorator receives a function and returns a replacement, which is how classmethod and staticmethod are used.
Q 24Which of the following is NOT something annotations like `x: int` give you in Python?
Enforcement at runtime
Python remains a dynamically typed language, so type hints are primarily for developer guidance and static analysis tools, not for enforcing type checking at runtime.
Q 25Which built-in type lets a set be stored as an element of another set?
`frozenset`
`frozenset` is hashable because it cannot be modified, so `{frozenset({1, 2})}` is legal; ordinary sets, lists and dicts are unhashable and raise TypeError as set elements.
Q 26Because of the GIL, what do CPython programs typically use to work across multiple CPU cores?
Multiple processes
Threads still help for I/O-bound work, but for CPU-bound work the multiprocessing module or C extensions that release the lock are the usual answer.
Q 27What is the main advantage of using Python's `enumerate()` function?
It pairs each item with a running count
The `enumerate()` function adds a counter to an iterable and returns it as an enumerate object, typically used in loops to access both the index and the value of items simultaneously, simplifying code and reducing errors.
Q 28In Python's `asyncio` library, what is the role of an 'event loop'?
It runs tasks, callbacks and network I/O
The event loop is the central execution mechanism in `asyncio`, orchestrating the execution of coroutines, managing I/O operations, and scheduling callbacks to enable single-threaded concurrency.
Q 29What is the purpose of `pass` in Python?
To stand in where a statement is required
The `pass` statement in Python is a null operation; it does nothing. It is used as a placeholder where a statement is syntactically required but you don't want any code to execute.
Q 30Which operator is used for exponentiation in Python?
**
The double asterisk (**) operator is used for exponentiation in Python, calculating the power of a number (e.g., `2 ** 3` evaluates to 8).