Python

Here is a quiz about “Python”.

At the end of the quiz, you’ll see your result. Retry the wrong answer(s) to discover the right one(s).

Warning

If your score is below average, call SED immediately ! 😆. Seriously, please come and talk with us to avoid doing major mistakes.

The button provides some help !

--- primary_color: steelblue --- ## Commentary How to comment in Python ? 1. [x] using `#` 1. [ ] using `//` 1. [ ] using `--` 1. [ ] using `%` ## Modules What's a Python **module** ? 1. [x] a file with a `.py` extension 1. [ ] a directory with an `__init__.py` file 1. [ ] a component of `pip` ## Packages What's a Python **package** ? 1. [ ] a file with a `.py` extension 1. [x] a directory with an `__init__.py` file 1. [ ] a component of `pip` ## Virtual environments What's the advantage of using virtual environments (venv, pipenv, virtualenv, and so on) ? > 2 good answers - [x] segregate dependencies of a project from system packages - [x] easily manage differents python version - [ ] simplify the installation of python packages - [ ] minimize the hard disk usage ## Package installation How can you install a python package ? > Let's consider we're using a debian-based linux here ;) - [x] `pip install ` - [x] `conda install ` - [x] `sudo apt install python-` - [ ] `python install ` ## Built-in : zip & range What is the result of the following code ? ```python for a, b in zip("toto", range(3)): print(a, b) ``` 1. [x] ```shell t 0 o 1 t 2 ``` 1. [ ] ```shell t 0 o 1 t 2 o 3 ``` 1. [ ] ```shell t 0 o 1 t 2 o 0 ``` ## Built-in : map & filter What is the result of the following code ? ```python t = [0, 5, 10, 15, 20, 25, 30] filtered_t = filter(lambda x: x % 2 == 1, t) print(list(map(print, filtered_t))) ``` 1. [x] ```shell 5 15 25 [None, None, None] ``` 1. [ ] ```shell [5, 15, 25] ``` 1. [ ] ```shell 5 15 25 [5, 15, 25] ``` ## Buit-in : string In python, strings are: 1. [x] immutable 1. [ ] mutable ## Built-in : dict In python, does dictionary preserve the insertion order ? > 2 good answers - [ ] no - [ ] yes, by design since python 1.0 - [x] yes, by CPython implementation since 3.6 - [x] yes, by design since 3.7 ## Function Suppose we have a function `f` and the following calls are valid: ```python f(alpha=2) f(1, 2, 3) f(1, beta=2) ``` What could be the signature of `f` ? > 2 good answers - [x] `def f(*args, alpha=1, beta=1):` - [x] `def f(*args, **kwargs):` - [ ] `def f(x, y, z, alpha=1, beta=1):` - [ ] `def f(*args, alpha, beta):` ## pip Select the right answers about pip - [x] `pip` is the standard package manager for python - [ ] `pip` is a virtual environment manager - [ ] `pip` is a registry to store python package ## conda Select the right answers about conda - [x] `conda` is a package manager for python - [x] `conda` is a virtual environment manager - [ ] `conda` is a registry to store python package ## pip vs conda Does `pip install ` and `conda install ` is always equivalent ? Are we sure that the installed packages are the same ? > Does `pip` and `conda` use the same package registry ? ;) - [ ] yes - [x] no ## pycache What's a `.pyc` file ? > 2 answers here - [x] a file created by the Python interpreter when a module is imported - [x] a file containing bytecode - [ ] a cython file ## Wh@t's this ? How do you call the instruction beggining by `@` in the following sample ? ```python @stuff def func(): pass ``` 1. [ ] annotation 1. [x] decorator ## Classes : Diamond problem Select the right answers about Python's inheritance 1. [ ] Python forbid multiple inheritance 1. [x] Python solves the diamond problem with a method resolution order 1. [ ] Python developer have to solve the diamond problem explicitly ## Classes : Attributes Consider the following code ```python class Foo: def __init__(self): self.a = 0 self._a = 1 self.__a = 2 foo = Foo() ``` Which of the following assert will pass ? > Beware of name mangling (see [PEP-8](https://peps.python.org/pep-0008/)) ! - [x] `assert(foo.a == 0)` - [x] `assert(foo._a == 1)` - [ ] `assert(foo.__a == 2)`

The quiz only runs in your browser. Even if your score is bad ! 😉

No personnal datas about you or your score are kept. Only an anonymous ratio is store to help us to build future tutorials.