Python initiation : relecture.
This commit is contained in:
parent
ae9bdf13fc
commit
f8818bff93
|
@ -1,8 +1,22 @@
|
|||
# Python
|
||||
|
||||
Par
|
||||
|
||||
<!-- .slide: data-background="static/background.jpg" -->
|
||||
|
||||
Julien Palard <julien@palard.fr>
|
||||
|
||||
https://mdk.fr
|
||||
|
||||
notes:
|
||||
|
||||
Juste pour le doctest :
|
||||
|
||||
Introduce yourself!
|
||||
|
||||
Ça couvre les types de bases survol quelques strucutres de contrôle,
|
||||
et quelques fonctions natives.
|
||||
|
||||
Et juste pour le doctest :
|
||||
|
||||
```python
|
||||
import random
|
||||
|
@ -23,22 +37,6 @@ recettes = [
|
|||
```
|
||||
|
||||
|
||||
## Python
|
||||
|
||||
par
|
||||
|
||||
Julien Palard <julien@palard.fr>
|
||||
|
||||
https://mdk.fr
|
||||
|
||||
notes:
|
||||
|
||||
Introduce yourself!
|
||||
|
||||
Ça couvre les types de bases survol quelques strucutres de contrôle,
|
||||
et quelques fonctions natives.
|
||||
|
||||
|
||||
## Python : Introduction
|
||||
|
||||
Python est un langage de programmation permettant de s'exprimer de
|
||||
|
@ -49,16 +47,27 @@ manière **concise** et **lisible**.
|
|||
|
||||
YouTube, Dropbox, Reddit, Instagram, Spotify, NASA…
|
||||
|
||||
![](static/Black-hole-M87.jpg)
|
||||
<img src="static/Black-hole-M87.jpg" style="width:60%">
|
||||
|
||||
|
||||
## Combien utilisent Python ?
|
||||
## Combien ?
|
||||
|
||||
![](static/Evolution_of_Python.png)
|
||||
<a href="https://git.afpy.org/mdk/python-versions">
|
||||
<img src="https://git.afpy.org/mdk/python-versions/media/branch/main/pypi-download-counts.png" style="width:90%">
|
||||
</a>
|
||||
|
||||
::: notes
|
||||
|
||||
https://insights.stackoverflow.com/trends
|
||||
Oui ça fait ~175TB/jour sur PyPI.org.
|
||||
|
||||
https://insights.stackoverflow.com/trends baisse en 2023, pourquoi ?
|
||||
|
||||
|
||||
## Quelle version ?
|
||||
|
||||
<a href="https://git.afpy.org/mdk/python-versions">
|
||||
<img src="https://git.afpy.org/mdk/python-versions/media/branch/main/python-versions-lines.png" style="width:90%">
|
||||
</a>
|
||||
|
||||
|
||||
## Installation
|
||||
|
@ -424,7 +433,7 @@ True
|
|||
## Travailler avec les ensembles
|
||||
|
||||
```pycon
|
||||
>>> {"farine", "sel"} | {"œuf", "sel"} == {"sel", "farine", "œuf"}
|
||||
>>> {"farine"} | {"œuf", "sucre"} == {"sucre","farine","œuf"}
|
||||
True
|
||||
```
|
||||
|
||||
|
@ -455,16 +464,6 @@ TypeError: can't multiply sequence by non-int of type 'str'
|
|||
```
|
||||
|
||||
|
||||
## Mais en cas d'ambiguité…
|
||||
|
||||
```pycon
|
||||
>>> {"farine", "levure"} + {"sel", "œuf"}
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
TypeError: unsupported operand type(s) for +: 'set' and 'set'
|
||||
```
|
||||
|
||||
|
||||
# Les variables
|
||||
|
||||
## Affectation
|
||||
|
@ -619,7 +618,7 @@ chaînes.
|
|||
['farine', 'sel', 'sucre']
|
||||
```
|
||||
|
||||
## Les importer des modules
|
||||
## importer des modules
|
||||
|
||||
```pycon
|
||||
>>> from random import choice
|
||||
|
@ -708,10 +707,8 @@ sel
|
|||
>>> ingredient = ingredients[1]
|
||||
>>> print(ingredient)
|
||||
farine
|
||||
>>> ingredient = ingredients[2]
|
||||
>>> print(ingredient)
|
||||
sucre
|
||||
```
|
||||
…
|
||||
|
||||
|
||||
## for
|
||||
|
@ -1254,10 +1251,10 @@ préciser peut être : "dont on connaît à toutes les étapes du programme".
|
|||
## Exemple
|
||||
|
||||
```python
|
||||
class Point:
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
class Recette:
|
||||
def __init__(self, nom, ingrédients):
|
||||
self.nom = nom
|
||||
self.ingrédients = ingrédients
|
||||
```
|
||||
|
||||
Notes: On connaît les attributs.
|
||||
|
@ -1266,10 +1263,11 @@ Notes: On connaît les attributs.
|
|||
## Exemple
|
||||
|
||||
```pycon
|
||||
>>> ISIN = {
|
||||
... "GLE": "FR0000130809",
|
||||
... "PARRO": "FR0004038263",
|
||||
... "AM": "FR0000121725",
|
||||
>>> ingrédients = {
|
||||
... 'farine': 1000,
|
||||
... 'eau': 615,
|
||||
... 'levure': 10,
|
||||
... 'sel': 20
|
||||
... }
|
||||
```
|
||||
|
||||
|
@ -1399,12 +1397,13 @@ Notes: C'est l'occasion de parler de assert.
|
|||
|
||||
```python
|
||||
from hypothesis import given
|
||||
from hypothesis.strategies import integers
|
||||
from hypothesis.strategies import floats
|
||||
|
||||
@given(floats())
|
||||
def test_temperature_conversions(temp):
|
||||
assert fahrenheit_to_celsius(
|
||||
celsius_to_fahrenheit(temp)) == temp
|
||||
|
||||
@given(integers(min_value=2,
|
||||
max_value=1000))
|
||||
def test_fib(i):
|
||||
assert fib(i) == fib(i-1) + fib(i-2)
|
||||
```
|
||||
|
||||
|
||||
|
@ -1425,15 +1424,6 @@ Notes: Prérequis: pip et venv.
|
|||
Pas plus de 7.
|
||||
|
||||
|
||||
## Garder son code lisible
|
||||
|
||||
Attention au code vieillissant, au « je ne rajoute qu'une ligne ou
|
||||
deux à cette fonction et c'est réglé ».
|
||||
|
||||
Notes: Deux ans après la fonction fait 800 lignes, et personne ne l'a
|
||||
vu venir. flake8 peut aider.
|
||||
|
||||
|
||||
## Les « linters »
|
||||
|
||||
Il existe plusieurs outils pour « relire » votre code :
|
||||
|
@ -1518,8 +1508,6 @@ breakpoint()
|
|||
|
||||
## PYTHONDEVMODE=y
|
||||
|
||||
Et `./configure --with-pydebug`.
|
||||
|
||||
Notes: Voir mon bashrc :] Surtout "viable" depuis la 3.8.
|
||||
|
||||
|
||||
|
@ -1625,10 +1613,10 @@ y → 12
|
|||
C'est transformer une chaîne en octets, pour son transport ou stockage :
|
||||
|
||||
```pycon
|
||||
>>> "L'été".encode()
|
||||
b"L'\xc3\xa9t\xc3\xa9"
|
||||
>>> list("L'été".encode())
|
||||
[76, 39, 195, 169, 116, 195, 169]
|
||||
>>> "Pâte à crêpe".encode()
|
||||
b'P\xc3\xa2te \xc3\xa0 cr\xc3\xaape'
|
||||
>>> list("Pâte à crêpe".encode())
|
||||
[80, 195, 162, 116, 101, 32, 195, 160, 32, 99, 114, 195, 170, 112, 101]
|
||||
```
|
||||
|
||||
|
||||
|
@ -1637,8 +1625,8 @@ b"L'\xc3\xa9t\xc3\xa9"
|
|||
C'est le contraire ...
|
||||
|
||||
```pycon
|
||||
>>> bytes([76, 39, 195, 169, 116, 195, 169]).decode()
|
||||
"L'été"
|
||||
>>> b'P\xc3\xa2te \xc3\xa0 cr\xc3\xaape'.decode()
|
||||
'Pâte à crêpe'
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
@ -1666,4 +1654,7 @@ variable.
|
|||
|
||||
## Les PyCons
|
||||
|
||||
La PyConFr (tous les ans, sauf cette année) ! Les meetups locaux hors période de pandémie !
|
||||
La PyConFR (tous les ans) ! Les meetups locaux !
|
||||
|
||||
- https://pycon.fr
|
||||
- https://discuss.afpy.org/c/meetups/12
|
||||
|
|
Loading…
Reference in New Issue