Skip to content

96 facts

96 Fun Facts About Python Programming

Learn something new, then test yourself with the quiz.

Know these facts? Prove it.

Take the 100-question quiz
1

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.

2

Which keyword ends a function call and hands a value back to the caller?

`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.

3

In what year was the first public version of Python released?

1991's release on February 20 came from Guido van Rossum, who had started the project as a Christmas hobby in 1989.

4

What is the official style guide for Python code, promoting readability and consistency?

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.

5

How does Python define code blocks, unlike languages that use curly braces?

Python's design philosophy emphasizes code readability with the use of significant indentation to define code blocks.

6

What is the standard package installer for Python called?

pip's name is a recursive acronym, 'pip installs packages'; npm, gem and apt serve JavaScript, Ruby and Debian respectively.

7

Which Python data type is mutable?

List elements can be modified after creation, while tuples, strings and integers are immutable, which is why only the latter can be dictionary keys.

8

In CPython, what does the Global Interpreter Lock (GIL) actually do?

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.

9

Which OOP principle bundles data and the methods that operate on it into a single class?

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.

10

Which category do `int`, `float`, and `complex` data types belong to in Python?

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.

11

Which 'fully loaded' Python web framework handles authentication, admin and RSS out of the box?

Django's own tagline is 'the web framework for perfectionists with deadlines'; Flask and FastAPI are deliberately slimmer micro-frameworks.

12

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.

13

Which aphorism is NOT in 'The Zen of Python' (PEP 20)?

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.'

14

Which Python library is foundational for numerical computing with multi-dimensional arrays?

NumPy (Numerical Python) is the foundational package for numerical computing in Python, providing support for multidimensional arrays and matrices.

15

In what year did Python 2 officially reach End-of-Life?

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.

16

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.

17

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`.

18

Which of the following is NOT a valid Python identifier?

`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.

19

To open a file named 'example.txt' for writing, which mode would you use in the `open()` function?

'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.

20

What does a Python class's `__init__` method do?

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.

21

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.

22

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.

23

What does a Python decorator do?

Applied with the @wrapper syntax, a decorator receives a function and returns a replacement, which is how classmethod and staticmethod are used.

24

Which of the following is NOT something annotations like `x: int` give you 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.

25

Which built-in type lets a set be stored as an element of another set?

`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.

26

Because of the GIL, what do CPython programs typically use to work across multiple CPU cores?

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.

27

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.

28

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.

29

What is the purpose of `pass` 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.

30

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).

31

What is a 'comprehension' such as `[x*2 for x in nums]` 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.

32

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'>`.

33

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.

34

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.

35

Which built-in function reads a line typed by 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.

36

What is the correct way to load the standard library's `os` module for use in your code?

`import os` binds the whole module to the name os; Python has no include, use or require keyword, and `from math import sqrt` is the form that pulls in a single name.

37

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.

38

Which built-in type stores data as key-value pairs?

A dictionary (`dict`) maps each unique key to a value, as in `{'name': 'Ada'}`; since Python 3.7 it also preserves insertion order.

39

What does the `break` statement do inside a `for` or `while` block?

The `break` statement is used to exit out of the innermost `for` or `while` loop immediately, transferring control to the statement following the loop.

40

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.

41

What is a 'docstring' in Python?

A docstring is the first string literal in a module, class or function body; the interpreter stores it as __doc__, which help() prints, while ordinary comments are discarded at parse time.

42

What is the purpose of the built-in `map()` in Python?

In Python 3 map() returns a lazy iterator rather than a list, so you wrap it in list() if you need the results all at once.

43

Which of these is the correct syntax for starting a new type definition 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`).

44

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'>`.

45

What does the expression `10 // 3` evaluate to in Python?

`//` is floor division: 10 // 3 rounds down to the integer 3, whereas 10 / 3 returns the float 3.3333 and 10 % 3 gives the remainder 1.

46

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.

47

What command adds a third-party library from PyPI to your environment?

`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.

48

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.

49

Which Python list method removes an item by its index and hands the item back to you?

`pop()` removes the item at a given index and returns it; with no index it takes the last item, while `remove()` works by value and `delete()` does not exist.

50

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).

51

Which line correctly defines 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.

52

What is the result of joining the literals `"hi"` and `" mom"` with `+` in Python?

The + operator concatenates strings and * repeats them, so `"ab" * 3` gives `"ababab"`.

53

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.

54

What does the conventional first parameter `self` refer to inside a Python class body?

The object the call was made on is what `self` holds; it is only a convention, not a keyword, so you could name it anything.

55

Which Python module handles operating system tasks like 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.

56

How can you stop a mutable fallback value like `items=[]` from being shared between calls?

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.

57

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.

58

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.

59

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.

60

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.

61

Python was designed as a successor to which language that van Rossum had helped develop at CWI?

ABC, a teaching language developed at CWI in Amsterdam and itself inspired by SETL, was the language Python set out to improve on; van Rossum began implementing Python in December 1989.

62

What is the nickname of the := syntax introduced in Python 3.8?

The walrus operator, so called because := looks like eyes and tusks, arrived with PEP 572 in Python 3.8; it assigns a value inside a larger expression so a result can be tested and reused in one line.

63

What informal title did Guido van Rossum hold over Python until he stepped down on 12 July 2018?

Benevolent Dictator for Life, or BDFL, was the title; after the bruising PEP 572 debate he announced a 'permanent vacation' from it on 12 July 2018.

64

Van Rossum named Mondrian, a code-review tool he built at Google, after what?

A related project, Rietveld, honoured Dutch designer Gerrit Rietveld; he worked at Google from 2005 to 2012.

65

Which company did van Rossum join in November 2020, coming out of retirement?

Microsoft hired him as a Distinguished Engineer in its Developer Division in November 2020, a year after he had retired from Dropbox in October 2019.

66

What was the name of Google's 2009 project to speed up the Python interpreter five-fold using LLVM?

Unladen Swallow, launched by Google engineers in 2009, aimed for a fivefold speed-up by compiling to LLVM and better multithreading; it was abandoned by 2011 and never merged into CPython.

67

In which year was Python 2.0, with list comprehensions and Unicode support, released?

Python 2.0 arrived on 16 October 2000 with list comprehensions, Unicode strings and a cycle-detecting garbage collector, and it moved development to SourceForge's more open, community-backed process.

68

Which December 2008 Python release was a major, backward-incompatible revision?

Python 3.0, released on 3 December 2008, broke compatibility by making print a function and strings Unicode by default; many features were backported to 2.6 and 2.7 to ease migration.

69

What body did Python's core developers elect in January 2019 to lead the project?

A five-member Steering Council, created by PEP 13, won the core-developer vote that closed on 4 February 2019; it replaced one-person rule by the language's creator after his July 2018 'permanent vacation'.

70

Which utility, shipped with Python through 3.12, translated Python 2 code to Python 3?

2to3 rewrote common incompatibilities such as the print statement but could not fix every semantic change; its lib2to3 library was deprecated in 3.11 and removed in Python 3.13.

71

Python 1.0 (1994) got lambda, map, filter and reduce from a hacker of which language?

Lisp: van Rossum wrote that the four functions came courtesy of a Lisp hacker who missed them and submitted working patches; for Python 3 he managed only to move reduce into functools.

72

Python's original module system was borrowed from which language?

Modula-3 supplied the module system and the shape of the exception model, to which Python added an else clause; van Rossum called the module 'one of Python's major programming units'.

73

Instead of foo and bar, which placeholder names are traditional in Python literature?

They come from the Monty Python sketch set in a cafe where every dish contains Spam, and the official documentation is sprinkled with similar references.

74

What indent size does Python officially recommend for each block level?

Four spaces per level; because indentation delimits blocks, a program's visual shape matches its logical structure, the so-called off-side rule.

75

Which external tool uses Python's optional type annotations to catch errors?

mypy, started by Jukka Lehtosalo in 2012, reads the optional annotations and reports type errors before the code runs; the same project ships mypyc, a compiler that uses those hints for speed.

76

What does the expression 4 % -3 evaluate to in Python?

Python's modulo takes the sign of the divisor, unlike C, where the remainder takes the sign of the dividend.

77

Which symbol does Python reserve as its matrix-multiplication operator?

It was added in Python 3.5 at the request of the scientific community so that arrays could multiply without nested function calls.

78

What does 5/2 evaluate to in Python 3?

2.5: Python 3 made / true division that always returns a float, whereas Python 2 truncated 5/2 to 2; the // operator exists for anyone who still wants the floor.

79

Which new syntax did Python 3.11 add for handling exception groups?

It lets one handler match several exceptions raised together, such as from concurrent tasks, while a regular except clause still handles single errors.

80

CPython first compiles source code into what before it is interpreted?

Bytecode: CPython compiles each module to instructions for its own virtual machine and caches them as .pyc files in __pycache__ folders, which is why it counts as both compiler and interpreter.

81

Which conference does the Python Software Foundation run as its leading community event?

PyCon US is the flagship; the foundation, launched in March 2001, also owns the trademark on the word 'Python' and the two-snakes logo.

82

Jython, called JPython until 1999, is a Python implementation built to run on what?

The Java virtual machine: Jython compiles Python to Java bytecode and maps Python threads onto JVM threads, so it has no global interpreter lock; Jim Hugunin started it as JPython in 1997.

83

Flask's name is a play on which earlier Python microframework?

Bottle: Armin Ronacher chose Flask as a wink at Marcel Hellkamp's earlier single-file microframework; the project began as an April Fool's joke in 2010 and grew into a serious framework.

84

Django, the framework born at the Lawrence Journal-World newspaper, is named after what?

Django Reinhardt, the Belgian-born Romani jazz guitarist, gave the framework its name; co-creator Adrian Holovaty plays gypsy jazz himself, and Django went public under a BSD licence in July 2005.

85

The pandas library takes its name from which econometrics term?

Panel data, the econometrics term for multidimensional time series, gave pandas its name; Wes McKinney began it at AQR Capital in 2008 and the firm open-sourced it in 2009.

86

Matplotlib's name blends 'plot' and 'library' with which numerical software?

MATLAB: John D. Hunter began matplotlib in 2003 to replicate MATLAB's plotting in Python; the Event Horizon Telescope team used it while producing the first black-hole image in 2019.

87

Project Jupyter's name refers to which three core programming languages?

Julia, Python and R were the three languages the 2014 spin-off from IPython first targeted, hence 'Jupyter'; the name and logo also nod to Galileo's notebooks on the moons of Jupiter.

88

The popular Requests HTTP library is implemented as a wrapper around which other library?

urllib3 handles Requests' connection pooling and retries underneath its friendlier API; author Kenneth Reitz released Requests in 2011 and moved it under the Python Software Foundation in 2019.

89

By what Monty Python-inspired nickname is the Python Package Index also known?

The Cheese Shop nickname comes from the Monty Python sketch in which a cheesemonger stocks no cheese; cheeseshop.python.org was once the index's address, and pip pulls from it by default.

90

Tkinter translates its calls into commands for an interpreter of which embedded language?

Tcl: Tkinter is a thin layer over the Tk toolkit, which runs inside a Tcl interpreter embedded in the Python process; the name is short for 'Tk interface' and it ships with the official installers.

91

Python's bundled beginner editor is thought to partly honour which Monty Python member?

Eric Idle is the Monty Python member IDLE's name winks at; officially it stands for Integrated Development and Learning Environment, and it has shipped with CPython since version 1.5.2b1 in 1999.

92

Which education-focused fork of MicroPython was first released in July 2017?

CircuitPython, Adafruit's beginner-oriented fork, reached 1.0 in July 2017; MicroPython itself came from Damien George's 2013 Kickstarter, which shipped the 'pyboard', and the two support different boards.

93

The pytest testing framework originated inside which alternative Python implementation?

PyPy: Holger Krekel wrote the original py.test as the test runner for the PyPy project in 2004; the tool kept the py.test name until version 3.0.0 in August 2016 made 'pytest' the recommended command.

94

The HTML parser Beautiful Soup is named after a poem from which book?

Alice in Wonderland: the Mock Turtle sings 'Beautiful Soup' in Lewis Carroll's book; Leonard Richardson started the parser in 2004, and the name also puns on 'tag soup', badly structured HTML.

95

Scrapy builds crawling projects around self-contained crawlers it calls what?

Spiders are Scrapy's classes that define how a site is crawled and parsed; the framework began at the London e-commerce firm Mydeco in 2008 and was later maintained by Scrapinghub, renamed Zyte in 2021.

96

Mojo, a Python-like language, comes from a firm co-founded by which language's architect?

Swift's creator Chris Lattner, who also started LLVM, co-founded Modular Inc in 2022; Mojo builds on the MLIR compiler framework so it can target GPUs and other accelerators.

Think you know Python Programming?

Put these facts to the test with the interactive quiz.

Take the 100-question quiz

Teaching Python Programming?

Make a custom quiz — handy for classrooms and study groups.

Make a quiz on anything

Related quizzes