Who designed the Python language?
Answer : Guido van Rossum
Guido van Rossum designed Python, whose first published version dates from 1991.
Revise Python: here is a selection of questions of every level, with the answer and an explanation. To test yourself without seeing the answers, play the quizzes.
Play the Python quizzesAnswer : Guido van Rossum
Guido van Rossum designed Python, whose first published version dates from 1991.
Answer : From the British comedy troupe Monty Python
Guido van Rossum chose this name in reference to the British comedy troupe Monty Python.
Answer : Indentation
In Python, indentation is not a display detail: it delimits the blocks of if, for, functions and classes.
Answer : float
A number written with a decimal point is of type float; int designates integers without a decimal part.
Answer : elif
elif is short for else if: it adds a condition after the if, before an optional else.
Answer : The list
A list, written between square brackets, can be modified (adding, removing, replacing); a tuple, written between parentheses, cannot.
Answer : {'nom': 'Ada'}
A dictionary is written between braces, in the form key: value; {'nom', 'Ada'} without a colon is a set.
Answer : [0, 1, 2]
range(3) starts at 0 and stops before 3: it produces 0, 1 and 2, that is three values.
Answer : [1, 4, 9]
A list comprehension goes through the sequence and computes each element: here n * n gives 1, 4, then 9.
Answer : 2
A parameter that has a default value receives it when the caller does not provide an argument for it.
Answer : A dictionary of the named arguments
**kwargs gathers the arguments passed with a name (word=value) into a dictionary.
Answer : 'Bon'
The slice [start:end] takes the indexes from start and stops before end: here the indexes 0, 1 and 2, that is 'Bon'.
Answer : self
The first parameter of an instance method receives the current object; the convention is to name it self.
Answer : Isolating the packages installed for a given project
A venv is a folder that isolates the packages of a project, to avoid version conflicts between projects.
Answer : except
The except block runs when a matching exception is raised in the try block; the rest of the try is then interrupted.
Answer : The file is closed automatically at the end of the block, even on error
with uses a context manager: the file is closed when the block ends, even if an error occurs.
Answer : A generator object, which produces the values one by one on request
A function with yield returns a generator: its body runs only when the next value is requested.
Answer : It raises the StopIteration exception
next() returns the next item; with no item left, the StopIteration exception signals the end of the iteration, which the for loop catches.
Answer : A function that takes a function as an argument and returns a modified function
A decorator is applied with @ above a function; a classic example is a decorator that measures the duration of a call.
Answer : It allows only one thread to run Python bytecode at a time
The GIL is the lock of the CPython interpreter: only one thread runs Python bytecode at a time, which limits the parallelism of computations.
Answer : It suspends the coroutine while waiting for an awaitable, without blocking the event loop
await suspends the coroutine until the awaited object is ready, and the event loop can run other tasks in the meantime.
Answer : Nothing: the annotation does not influence the execution
Annotations are used by tools such as mypy and for readability; the interpreter neither checks nor converts them at run time.
Answer : __len__
len(obj) calls the __len__ method defined in the class of the object, which must return an integer.
Answer : copy.copy duplicates only the first level; deepcopy also duplicates the sublists
copy.copy creates a new outer object, but its sub-objects stay shared; deepcopy also duplicates the nested objects.