| @@ -1,165 +1,22 @@ | |||||
| ### Introduction | |||||
| questions préliminaires: | |||||
| * Historique du langage: | |||||
| * qui est sous linux? | |||||
| * qui est sous mac? | |||||
| * qui est sous windows? | |||||
| * création par Guido pour l'enseignement | |||||
| * Monty Python | |||||
| * le grand schisme 2/3. | |||||
| * Meilleur nul part, excellent partout | |||||
| apres install de python: | |||||
| * Utilisation de Python | |||||
| * qui a 3.8? | |||||
| * qui a 3.7? | |||||
| * qui a 3.6? | |||||
| * qui a 3.5? # warning: no f-string there! | |||||
| * Sciences (physique, chimie ...) | |||||
| * Animation | |||||
| * Sites web | |||||
| * ... | |||||
| * Ligne de commande | |||||
| * Langage de 'glue' | |||||
| macOS azerty: | |||||
| ### Le REPL | |||||
| * S'assurer que tous les étudiants peuvent lancer le REPL | |||||
| Notions: | |||||
| * Entiers et flottants (via maths basiques: + * - /) | |||||
| * Grouper avec des parenthèses. | |||||
| * Booléens | |||||
| * Variables | |||||
| * Fonctions: | |||||
| * `quit()` | |||||
| ### Du code dans un fichier | |||||
| Oups, les variables disparaissent quand on ferme le REPL. | |||||
| Solution: les mettre dans un fichier `.py`. | |||||
| ```python | |||||
| a = 1 | |||||
| b = 2 | |||||
| c = a+b | |||||
| print(c) | |||||
| ``` | |||||
| S'assurer que les étudiants peuvent: | |||||
| * `cd` dans le bon répertoire | |||||
| * Lancer `python <lefichier.py`. | |||||
| Notions: | |||||
| * Fonction print() | |||||
| * Commentaires | |||||
| * Définir notre propre fonction: | |||||
| * Paramètres | |||||
| * Indentation | |||||
| * Deux-points | |||||
| * return() | |||||
| ```python | |||||
| # ceci est un commentaire | |||||
| def add(a, b): | |||||
| return a + b | |||||
| a = 1 | |||||
| b = 2 | |||||
| c = add(a, b) | |||||
| print(c) | |||||
| ``` | |||||
| ### Chaînes de caractères | |||||
| * Guillemets simple et double | |||||
| * Concaténation implicite | |||||
| * Backslash et échappement: '\n', '\r', '\t' | |||||
| * Raw string 'r' | |||||
| * Triple-guillemets | |||||
| * Parenthèses | |||||
| * Addition avec '+' | |||||
| Notions: | |||||
| * types. On peut pas ajouter un entier à une strig | |||||
| * conversion avec `str()` | |||||
| ```python | |||||
| message = "Le total est: " + c | |||||
| print(message) | |||||
| ``` | |||||
| * Indexation | |||||
| ``` | |||||
| +---+---+---+---+---+---+ | |||||
| | P | y | t | h | o | n | | |||||
| +---+---+---+---+---+---+ | |||||
| 0 1 2 3 4 5 6 | |||||
| -6 -5 -4 -3 -2 -1 | |||||
| ``` | |||||
| * `len()` | |||||
| ### Flot de contrôle | |||||
| * if | |||||
| * while | |||||
| * `break`, `continue` | |||||
| * `for` | |||||
| * `range()` | |||||
| * On peut aussi itérer sur les strings | |||||
| ### Entrèe standard | |||||
| * input() | |||||
| Démo: "à quel nombre je pense" | |||||
| ```python | |||||
| secret = 42 | |||||
| print("Devine le nombre auquel je pense"): | |||||
| while True: | |||||
| reponse = input() | |||||
| if response > secret: | |||||
| print("Trop grand") | |||||
| if response < secret: | |||||
| print("Trop petit") | |||||
| print("Gagné") | |||||
| break | |||||
| ``` | |||||
| Notions: | |||||
| * Exceptions: si la conversion échoue | |||||
| ```python | |||||
| import random | |||||
| secret = random.randint(0, 100) | |||||
| ``` | |||||
| Notions: | |||||
| * imports | |||||
| * accès à un membre avec `.` | |||||
| Des liens: | |||||
| * La doc officielle (récemment traduite en français): | |||||
| https://docs.python.org/fr/3/tutorial/index.html | |||||
| * sametmax: http://sametmax.com/cours-et-tutos/. Note: ça y parle aussi de | |||||
| cul, donc pas à mettre entre toutes les mains ;-) | |||||
| * Fin! | |||||
| alt et ( pour { | |||||
| alt et ) pour } | |||||
| shift alt et ( pour [ | |||||
| shift alt et ) pour ] | |||||
| shift alt l pour | | |||||
| shift n pour ~ | |||||
| shift alt / pour \ | |||||