Plan du Chapitre
1 Introduction à Python
2 Structures de contrôle
3 Conteneurs standards
4 Fonctions
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 2 / 55
Plan du Chapitre
1 Introduction à Python
2 Structures de contrôle
3 Conteneurs standards
4 Fonctions
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 3 / 55
Python
Python est un langage de script:
Développé depuis 1989 par Guido van Rossum
Orienté objet (mais peut être utilisé quasi non-”objectivement”)
Open Source et gratuit
Portable
Simple à comprendre/ écrire
Versions:
Version 1.0 : 1990
Version 2.0 : 2000
Version 3.0 : 2008
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 4 / 55
Python
Avantages : Interpréteur permettant de tester n’importe quel petit bout
de code, compilation transparentes
Inconvénients : peut être lent
Que peut-on faire avec Python ?
Développement Web: Django, Pyramid, Zope, Plone,...
Calcul Scientifique: Numpy, Scipy, sage, ...
Représentation graphique: gnuplot, matplotlib, VTK, ...
GUIs: TkInter, PyGtk, PyQt,...
Manipulation d’images: Pillow, OpenCV-Python,...
Bases de données: MySQL, PostgrSQL, Oracle, ...
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 5 / 55
Règles d’écritures
La casse est significative
Le typage des variables est dynamique
Une instruction doit commencer en première colonne
L’indentation est obligatoire pour marquer les blocks
Si une instruction dépasse la taille d’une ligne, il est possible soit
d’écrire un caractère de continuation ou de mettre l’instruction entre
parenthèses
Exemples
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 6 / 55
Opérations de base
Affectation
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 7 / 55
Opérations de base
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 8 / 55
Chaines de caractères
Encadrées par des apostrophes (’ ’) ou des guillemets (” ”)
Les opérateurs sur les chaı̂nes permettent de concaténer, filtrer ou
extraire des parties des chaı̂nes de caractères entres elles.
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 9 / 55
Chaines de caractères
Exemple
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 10 / 55
Chaines de caractères
Exemple
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 11 / 55
Conversion entre types
La conversion de types permet de passer d’un type à l’autre.
La règle générale est de se servir du nom du type avec des
parenthèses.
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 12 / 55
print() / input()
print(msg) : imprime à l’écran une chaı̂ne de caractères donnée en
argument
input(msg): permet de récupérer une chaı̂ne de caractères tapée par
l’utilisateur (retourne une chaine)
Exemples :
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 13 / 55
Plan du Chapitre
1 Introduction à Python
2 Structures de contrôle
Structures alternatives
Structures itératives
3 Conteneurs standards
4 Fonctions
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 14 / 55
Les blocs
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 15 / 55
Les structures conditionnelles
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 16 / 55
Les structures conditionnelles
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 17 / 55
Conditions
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 18 / 55
Boucle for
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 19 / 55
Boucle for
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 20 / 55
Boucle while
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 21 / 55
Boucle while
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 22 / 55
Plan du Chapitre
1 Introduction à Python
2 Structures de contrôle
3 Conteneurs standards
Listes
Tuples
Ensembles
Dictionnaires
4 Fonctions
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 23 / 55
Listes
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 24 / 55
Manipulations des Listes
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 25 / 55
Manipulations des Listes
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 26 / 55
Exemples
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 27 / 55
Exemples
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 28 / 55
Exemples
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 29 / 55
Suppression d’un élément
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 30 / 55
Copie d’une liste
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 31 / 55
Tuple
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 32 / 55
Tuples
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 33 / 55
Ensembles
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 34 / 55
Opérations
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 35 / 55
Exemples
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 36 / 55
Dictionnaires
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 37 / 55
Accès à un élément
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 38 / 55
Principales méthodes
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 39 / 55
Exemple
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 40 / 55
Exemple
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 41 / 55
Plan du Chapitre
1 Introduction à Python
2 Structures de contrôle
3 Conteneurs standards
4 Fonctions
Définition
Arguments d’une fonction
Fonctions variadiques
Portée d’une variable
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 42 / 55
Définition
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 43 / 55
Exemples
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 44 / 55
Argument d’une fonction
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 45 / 55
Arguments nommés
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 46 / 55
Fonction Variadique
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 47 / 55
Fonction Variadique
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 48 / 55
Fonction Variadique
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 49 / 55
Exemple
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 50 / 55
Variable locale / globale
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 51 / 55
Variable locale / globale
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 52 / 55
Variable locale / globale
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 53 / 55
Enumerate() / zip()
Centre d’excellence IT - FSA Programmation Python A.U : 2024-2025 54 / 55