class: center, middle # Introduction à Python --- # Qu'est-ce que Python ? * Création par Guido van Rossum en **1989** * Langage de programmation **interprété** >* similaire à Perl, Ruby... * Adapté au **traitement** et à la **manipulation de fichiers texte** * Dernière version : **3.12** * Site officiel : **https://python.org** --- # Votre environnement de travail * Activation de l'environnement Conda pour la formation > ````bash > $ conda activate formation-python > ``` > > __!__ Cette instruction est à exécuter à chaque fois que vous ouvrirez une nouvelle session de terminal. * La documentation de conda est disponible en ligne : https://conda.io/projects/conda/en/latest/index.html. --- # Exécution de Python * Interpréteur Python : ```bash $ python Python 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ``` > *Remarque : pratique pour tester une fonctionnalité ou exécuter une instruction.* * Exécution d'un script Python : ```bash $ python mon_script.py ``` > *Remarques :* > * *l'extension d'un script Python est **.py**.* > *
l'exécution d'un script sera privilégié lors de l'exécution de plusieurs instructions.
--- class: justify # Commentaires & Indentation * Commentaire : ```python >>> # Ceci est un commentaire car précédé par un '#' ``` * Indentation : ```python >>> instruction1: ... instruction1_1 ... instruction1_2 ... instruction1_3 >>> instruction2 ```
Remarques :
l'instruction
instruction1
contient un
bloc d'instructions
constitué de trois instructions identifiables grâce à l'
indentation
du code (soit
4 espaces
, soit une
tabulation
).
l'
instruction 2
est en dehors du bloc d'instructions précédent (absence d'indentation).
--- # Utilisation de l'interpréteur Python * Lancement de l'interpréteur Python : ```bash $ python Python 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ``` * Affichage d'une chaîne de caractères dans l'interpréteur : ```python >>> print("Hello World") Hello World ``` * Utilisation de l'interpréteur comme une calculatrice : ```python >>> 5+3 8 ``` * Quitter l'interpréteur Python : ```python >>> exit() ``` --- # Mon premier script Python * **Énoncé** : créer un programme Python nommé « `hello.py` » permettant d'afficher les informations demandées en 5 minutes d'autonomie :
Je m'appelle Prénom Nom.
--- # Mon premier script Python * **Énoncé** : créer un programme Python nommé « `hello.py` » permettant d'afficher les informations demandées en 5 minutes d'autonomie :
Je m'appelle Prénom Nom.
* 1ère solution : ```python print("Je m'appelle Sandra Dérozier.") ``` * 2ème solution : ```python print('Je m\'appelle Sandra Dérozier.') ``` * exécution du script : ```bash $ python hello.py Je m'appelle Sandra Dérozier. ```