Learn something new, then test yourself with the quiz.
Know these facts? Prove it.
Take the QuizTake the Python Programming Quiz
1 plays
What is the name of the creator of the Python programming language?
Python was created by Guido van Rossum, who first released it in 1991.
From what popular British comedy series did the Python programming language get its name?
The name 'Python' was inspired by the classic BBC comedy series 'Monty Python's Flying Circus,' reflecting a desire for the language to be fun and approachable.
In what year was the first version of the Python programming language officially released?
Python was first released by Guido van Rossum on February 20, 1991.
What is the official style guide for Python code, promoting readability and consistency?
PEP 8, officially titled 'Python Enhancement Proposal 8,' is the style guide for Python code, created to ensure readability and consistency.
How does Python primarily define code blocks and structure, unlike many other languages that use curly braces?
Python's design philosophy emphasizes code readability with the use of significant indentation to define code blocks.
What is the name of the standard package installer for Python, used to install packages from the Python Package Index (PyPI)?
`pip` is the package installer for Python, allowing users to install packages from the Python Package Index and other indexes.
Which of the following Python data types is mutable?
Lists are mutable sequences, meaning their elements can be modified after creation, while tuples, strings, and integers are immutable.
What is the primary purpose of the Global Interpreter Lock (GIL) in CPython?
The GIL is a mutex that allows only one thread to execute Python bytecode at a time, even on multi-core machines, primarily to simplify memory management and ensure thread safety within the interpreter.
Which OOP principle refers to bundling data (attributes) and methods (functions) that operate on the data into a single unit or class?
Encapsulation involves bundling data (attributes) and methods (functions) that operate on the data into a single unit or class, helping to hide the internal state of the object.
Which category do `int`, `float`, and `complex` data types belong to in Python?
`int`, `float`, and `complex` are all fundamental numeric data types in Python used for different kinds of mathematical operations.
Which of these is a popular full-stack Python web framework known for its 'batteries included' approach?
Django is a high-level Python web framework often called 'batteries included' because it provides everything web developers need to get started out of the box, ideal for large-scale applications.
What 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.
Which of the following aphorisms is NOT part of 'The Zen of Python' (PEP 20)?
'The Zen of Python' (PEP 20) states, 'There should be one-- and preferably only one --obvious way to do it,' which contrasts with the Perl motto 'there is more than one way to do it.'
Which Python library is foundational for numerical computing, providing support for large, multi-dimensional arrays and matrices?
NumPy (Numerical Python) is the foundational package for numerical computing in Python, providing support for multidimensional arrays and matrices.
In what year did Python 2 officially reach its End-of-Life (EOL), meaning it no longer received official support or security updates?
Python 2.7.18, released in 2020, was the last release of Python 2, marking its official End-of-Life.
What keyword is used to define a function in Python?
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.
Which of the following Python data types is immutable?
Tuples are ordered, immutable collections of items, meaning their elements cannot be changed after creation. Integers, floats, strings, and frozensets are also immutable.
How do you add a single-line comment in Python?
The hash symbol (#) is used to denote a single-line comment in Python, with everything after it on the same line being ignored by the interpreter.
What will be the output of the following Python expression: `5 + 2 * 3`?
Python follows standard operator precedence rules, where multiplication (*) is performed before addition (+), so `2 * 3` evaluates to `6`, and `5 + 6` equals `11`.
Who created the Python programming language?
Guido van Rossum is the creator of the Python programming language, which he began working on in the late 1980s and early 1990s.
Which of the following is NOT a valid Python variable name?
Python variable names cannot start with a number. They must begin with a letter or an underscore, followed by letters, numbers, or underscores.
To open a file named 'example.txt' for writing, which mode would you use in the `open()` function?
The 'w' mode (write mode) is used to open a file for writing. If the file already exists, its contents are truncated; if it doesn't exist, a new file is created.
What is the primary purpose of the `__init__` method in a Python class?
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.
Which keyword is used in Python to create a generator function?
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.
What is the purpose of the `super()` function in Python?
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.
What does a Python decorator do?
A Python decorator is a function that takes another function as an argument, adds functionality to it, and then returns a new, modified function, allowing for reusable code and cleaner designs.
Which of the following is NOT a benefit of using type hints in Python?
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.
What is the primary characteristic of a `frozenset` compared to a regular `set` in Python?
`frozenset` is an immutable version of a `set`, meaning its elements cannot be changed after creation. This immutability also makes `frozenset` hashable, allowing it to be used as a dictionary key or an element in another set.
The Global Interpreter Lock (GIL) in CPython prevents which of the following?
The GIL is a mutex that allows only one thread to execute Python bytecode at a time, even on multi-core processors, thus preventing true parallel execution in multi-threaded CPU-bound programs within a single CPython process.
What is the main advantage of using Python's `enumerate()` function?
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.
In Python's `asyncio` library, what is the role of an 'event loop'?
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.
What is the purpose of the `pass` statement in Python?
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.
Which 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).
What is a 'list comprehension' in Python?
List comprehensions provide a concise way to create lists. They consist of brackets containing an expression followed by a `for` clause, then zero or more `for` or `if` clauses.
What will be the result of `type([])` in Python?
The `type()` function returns the type of an object. Square brackets `[]` are used to define a list in Python, so `type([])` will return `<class 'list'>`.
Which of the following statements correctly handles an error in Python?
Python uses `try`, `except` blocks for error handling. Code that might raise an exception is placed in the `try` block, and the `except` block handles specific exceptions. Optionally, `else` and `finally` blocks can be used.
What is the purpose of the `__name__ == '__main__'` idiom in Python scripts?
The `if __name__ == '__main__':` block allows code within it to execute only when the script is run directly, preventing it from running when the script is imported as a module into another script.
Which built-in function is used to get input from the user in Python 3?
The `input()` function in Python 3 is used to read a line of text from the user's input, returning it as a string. In Python 2, `raw_input()` served this purpose.
What is the correct way to import a module named `math` in Python?
The `import` statement is used to bring modules into the current namespace, allowing you to use functions and variables defined within that module, such as `import math`.
What is the output of `len('hello')`?
The `len()` function returns the number of items in an object. For a string, it returns the number of characters, so `len('hello')` is 5.
Which of the following data structures is an ordered, mutable collection that allows duplicate members?
A list in Python is an ordered, mutable collection of items that allows duplicate members, defined by square brackets `[]`.
What does the `break` statement do in a loop?
The `break` statement is used to exit out of the innermost `for` or `while` loop immediately, transferring control to the statement following the loop.
Which module in Python is commonly used for working with dates and times?
The `datetime` module provides classes for working with dates and times in both simple and complex ways, offering functionality for parsing, formatting, and arithmetic.
What is a 'docstring' in Python?
A docstring is a string literal used for documentation, providing a convenient way to associate documentation with Python modules, functions, classes, and methods.
What is the purpose of the `map()` function in Python?
The `map()` function applies a specified function to each item of an iterable (e.g., list, tuple) and returns a map object (an iterator) which can then be converted into a list or other iterable.
Which of these is used to define a class in Python?
Classes in Python are defined using the `class` keyword, followed by the class name and a colon, typically in PascalCase (e.g., `MyClass`).
What is the output of `print(type(10))`?
The `type()` function returns the type of the object passed to it. `10` is an integer literal in Python, so its type is `<class 'int'>`.
Which of the following is an example of a built-in mutable data type in Python?
Lists are mutable data types in Python, meaning their elements can be changed after they are created. Strings, integers, and tuples are immutable.
What is the primary benefit of using a `virtual environment` in Python?
Virtual environments allow Python developers to isolate project dependencies, ensuring that each project has its own set of libraries and dependencies, thus avoiding conflicts.
How do you install a Python package using `pip`?
`pip` is the standard package-management system used to install and manage software packages written in Python. The command `pip install package_name` downloads and installs the specified package.
What is the purpose of the `zip()` function in Python?
The `zip()` function takes multiple iterable arguments and returns an iterator that produces tuples, where the i-th tuple contains the i-th element from each of the input iterables.
Which of the following methods is used to remove an item from a list by its index?
The `pop()` method removes the item at a given index from the list and returns it. If no index is specified, it removes and returns the last item.
What does the `continue` statement do in a loop?
The `continue` statement causes the loop to skip the rest of the current iteration and immediately proceed to the next iteration (or terminate if there are no more iterations).
Which of these is a correct way to define a set in Python?
Sets in Python are unordered collections of unique items, defined by curly braces `{}`. `set()` can also be used to create an empty set or convert an iterable to a set.
What is the result of `"hello" + " world"` in Python?
The `+` operator concatenates strings in Python. When applied to two strings, it joins them together, resulting in `"hello world"`.
Which of the following is NOT a built-in exception in Python?
`TypeError`, `NameError`, and `SyntaxError` are built-in exception types in Python. `CustomError` would typically be a user-defined exception class.
What is the purpose of the `self` parameter in Python class methods?
The `self` parameter is a convention in Python (though not a keyword) that refers to the instance of the class, allowing methods to access and modify the object's attributes and other methods.
Which of the following modules provides functions for interacting with the operating system, such as file paths and environment variables?
The `os` module in Python provides a way of using operating system dependent functionality, such as reading or writing to a file system, managing paths, and interacting with environment variables.
How can you prevent a mutable default argument from causing unexpected behavior in a Python function?
Mutable default arguments are evaluated once when the function is defined, leading to shared state across calls. To avoid this, set the default to `None` and initialize a new mutable object inside the function if `None` is passed.
What is the purpose of the `yield from` expression in Python generators?
The `yield from` expression, introduced in PEP 380, is used to delegate parts of an operation to a subgenerator or another iterable, simplifying the code for complex generators.
Which of the following is true about Python's `async/await` syntax?
The `async/await` syntax, part of the `asyncio` library, is designed for writing single-threaded concurrent code, particularly effective for I/O-bound tasks, by allowing an event loop to switch between tasks while waiting for I/O.
What does MRO stand for in the context of Python's object-oriented programming?
MRO stands for Method Resolution Order, which is the order in which Python searches for a method in a class hierarchy, especially important in cases of multiple inheritance.
Which data type is optimized for fast lookup of unique elements and does not allow duplicates?
Sets are unordered collections of unique elements, making them ideal for membership testing and eliminating duplicates due to their underlying hash-table implementation for fast lookups.
What is the purpose of the `with` statement in Python?
The `with` statement is used to wrap the execution of a block with methods defined by a context manager, ensuring that setup and teardown actions (like opening and closing files) are handled correctly, even if errors occur.
What is a 'metaclass' in Python?
A metaclass in Python is a class whose instances are classes. It defines how classes are created and how they behave, allowing for advanced customization of class creation logic.
Put these facts to the test with our interactive quiz.
Take the QuizTeaching Python Programming?
Generate a custom quiz with AI — perfect for classrooms and study groups.
Create a Custom Quiz