![Page 1: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/1.jpg)
Introduction à la programmation
Python
000
![Page 2: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/2.jpg)
Premier "programme"
001
![Page 3: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/3.jpg)
Premier "programme"
002
![Page 4: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/4.jpg)
Commandes
Notion de variables:
a est une variable (qui vaut 7)b est une variable (qui vaut 2)
003
![Page 5: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/5.jpg)
Commandes
Notion de variables:
> 7
004
![Page 6: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/6.jpg)
Commandes
Affichage à l'écran:
> le resultat de 2+2 vaut 4
005
![Page 7: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/7.jpg)
Commandes
Types de variables:
a est un nombre (entier)
b est un nombre (à virgule)
c est un texte
a+b OK
a+cunsupported operand type(s) for +: 'int' and 'str'
006
![Page 8: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/8.jpg)
Commandes
Types de variables:
007
![Page 9: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/9.jpg)
Commandes
Variable nombre/texte:
ceci est du texte
ceci est un nombre
> 4+72+2> 15 008
![Page 10: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/10.jpg)
Commandes
Variable nombre/texte:
transforme un nombre en texte(str=string)
> 1278
009
![Page 11: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/11.jpg)
L'aide
Pour obtenir de l'aide sur une fonction:
help(nom_fonction)
ex. help(pow)
http://docs.python.org/2/index.html
http://docs.python.org/3/index.html
Site web:
010
![Page 12: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/12.jpg)
Ecriture dans un fichier
Ecrire ligne à ligne est fastidieux ...
On écrit d'abord dans un fichier texte
On lance Python sur le fichier
(.py = fichier texte lisible par Python)
011
![Page 13: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/13.jpg)
Editeur Python
Editeur de texte (attention à l'indentation)
- Linux: Kate- Window: par defaut, pyscripter
Editeur type Matlab: Spyder
012
![Page 14: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/14.jpg)
Python: le langage
Création en 1990 (C ~ 1973)
Scripts, manipulation texte, pas de scientifique
Module Numpy en 2005
Developpement du calcul scientifique
Python 2.0 en 2000Python 3.0 en 2009
Python devient un acteur majeur du monde du calculscientifique- beaucoup de modules (scientifique, visualisation, etc)- lisible- simple à écrire- language haut niveau- potentiellement optimisable 013
![Page 15: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/15.jpg)
Python: positionnementTout usage
Spécialisé
N'est pas prévupour du scientifique
Peut faire du scientifique
C++C
Python
Fortran
Java
Ada
JavaScript
PHP
Lua
Maple
Mathematica
MatlabPerl
Tcl
Basic
C#
014
![Page 16: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/16.jpg)
Python: positionnementSimple, Lisible
Complexe
C++
C
Python
Ada
Java
015
![Page 17: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/17.jpg)
Python: Les + / -
+ Langage très lisible
Lisibilité d'un code = Le + Important
Un code est beaucoup plus lue qu'écritLe code est sa propre documentationErreur facilement détectable = gain de temps
016
![Page 18: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/18.jpg)
+ Langage très lisible
Java
Python
Ce qui est simple s'écrit simplement
017
![Page 19: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/19.jpg)
+ Langage très lisible
C++ : occurence dans un conteneur
Python
Commentaires indispensables!!
Est-ce utile de commenter?
La généricités'écrit "naturellement"
018
![Page 20: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/20.jpg)
+ Langage très lisible
C
Python
Commentaires + qu'indispensables!!
...+ danger mémoire "run-time"
019
![Page 21: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/21.jpg)
Python: Les + / -
+ Langage très lisible
+ Algorithme proche du langage
+ Utilisé en industrie script
calcul
(apprentissage)
- Pas d'apprentissage "hardware"/OS
- Délicat pour code très volumineuxtypage dynamique
020
![Page 22: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/22.jpg)
Python VS
C + Aisance codage, clareté- Pas de contrôle bas niveau (embarqué, OS)- Lent
C++ + Clareté- Lent
Java + Simple, moins verbeux+ Applicable science (operateurs)- Moins répendu
Matlab + Vraie informatique, structures données+ Rapide- Moins "sucre syntaxique"
021
![Page 23: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/23.jpg)
Conditions: si, sinon
022
![Page 24: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/24.jpg)
Condition if"si"
(si a fois b est plus grand que 22)
023
![Page 25: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/25.jpg)
Condition if"si"
: début d'un bloc de traitement
espace => bloc d'instructions
024
![Page 26: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/26.jpg)
Condition if"si"
025
![Page 27: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/27.jpg)
Condition if / else"si / sinon"
si a fois b est supérieur à 22 alors "j'affiche ce message"sinon j'affiche "ceci est un autre message"
:
026
![Page 28: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/28.jpg)
Condition if / else"si / sinon"
si a est égale à 6 alors affiche "a vaut 6"sinon affiche "a ne vaut pas 6"
Cas particulier du test d'égalité
symbole ==test d'égalité
a=b
a==b
Math Code
affectation
test d'égalité(vaut vrai ou faux)
027
![Page 29: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/29.jpg)
L'indentation
Débatphilosophique ... religieux
!=
y y
L'indentation fait partie du code!!!
Ne s'execute pas!IndentationError: unexpected indent
028
![Page 30: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/30.jpg)
L'indentation
!=
y y
+ Force à la lisibilité du codeBon pour l'apprentissage
+/- Copié-coller difficileMais: copié-coller est à éviter
- Portabilité: compatibilité Tab, espaces, ... (éditeur obligatoire)
029
![Page 31: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/31.jpg)
Les listes d'éléments
030
![Page 32: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/32.jpg)
Ensemble éléments: Listes
1 7 5 9 -4 3[0] [1] [2] [3] [4] [5]
crochets [ ... ] indiquent une liste
indices:
contenu:
031
![Page 33: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/33.jpg)
Ensemble éléments: Listes
1 7 5 9 -4 3[0] [1] [2] [3] [4] [5]indices:
contenu: ??[6]
IndexError: list index out of range
032
![Page 34: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/34.jpg)
Ensemble éléments: Listes
Une liste peut contenir des mots
"pomme" "poire" "banane" "peche"
[0] [1] [2] [3]
033
![Page 35: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/35.jpg)
Ensemble éléments: Listes
Une liste peut contenir différents types
1.45 "un torchon" "une serviette"
[0] [1] [4]
-7
[2] [3]
1
034
![Page 36: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/36.jpg)
Ensemble éléments: ListesAjouter des éléments dans une liste
035
![Page 37: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/37.jpg)
Ensemble éléments: ListesSupprimer des éléments dans une liste
036
![Page 38: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/38.jpg)
Ensemble éléments: ListesCréer une "liste" particulière
4 5 6 7 8
8 5 2 -1
a
b
range(debut,fin,[increment])
stop 1 élémentavant fin
037
![Page 39: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/39.jpg)
Ensemble éléments: ListesNombre d'éléments d'une liste
038
![Page 40: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/40.jpg)
Ensemble éléments: ListesIndexation inverse
039
![Page 41: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/41.jpg)
Sous partie d'une liste
-4 5 -7 4 1 2 -2.20 1 2 3 4 5 6
ma_sous_liste_2
ma_sous_liste_1
040
![Page 42: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/42.jpg)
Trier une liste
unorderable typesstr()<int()
041
![Page 43: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/43.jpg)
Compter nombre d'occurences
042
![Page 44: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/44.jpg)
Insérer un élément dans une liste
4 7 4 8 65 1 7 9 -4 5 80 1 2 3 4 5 6 7 8 9 10
-3.12
4
043
![Page 45: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/45.jpg)
Supprimer par valeur
Ne supprime qu'une valeur (la première trouvée)
Différent de: del(ma_liste[k])!
supprime le kème élément (indice)
Recherche valeur et supprime l'élément
044
![Page 46: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/46.jpg)
Liste de listes
045
![Page 47: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/47.jpg)
Itération sur les listes
le mot clé "for"
046
![Page 48: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/48.jpg)
Créer des listes
Exemple pour
En francais: L = (k-2)^2 pour k variant dans [0,N[
En code
(** :puissance)
047
![Page 49: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/49.jpg)
La boucle "pour"
[ f(x) for x in nom_liste ]
Symbole d'une liste
Fonction à appliquer
nom de la variablequi est itérée
on itère
"dans" quoi
la liste que l'on parcourt
048
![Page 50: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/50.jpg)
Application
Calculer:
(|x| : abs(x))
049
![Page 51: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/51.jpg)
Application
Calculer:
(|x| : abs(x))
050
![Page 52: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/52.jpg)
Application
affichage (plot=dessine, show=montre à l'écran)
051
![Page 53: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/53.jpg)
Application
Avec les bonnes abscisses + echantillons
en rougedessinerdes
052
![Page 54: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/54.jpg)
Les fonctions
053
![Page 55: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/55.jpg)
Les fonctions
Remarque:
compliqué ... peu lisible!
On souhaiterait écrire:
avec f(k)= ... 054
![Page 56: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/56.jpg)
Les fonctions
055
![Page 57: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/57.jpg)
Les fonctions
def nom_fonction(argument) :
return valeur
Faire quelque chose ...
056
![Page 58: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/58.jpg)
Boucle "classique"
[ f(x) for x in nom_liste]
Remarque: Parfois/souvent f est - complexe - ne retourne rien / modifie x (la liste) - n'est écrite qu'une seule fois
for x in nom_liste:
f(x)
057
![Page 59: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/59.jpg)
Boucle "classique"
Exemple
a%breste de la division euclidienne
058
![Page 60: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/60.jpg)
Librairie mathématiqueet affichage
059
![Page 61: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/61.jpg)
Numpy: Array
array ressemble aux listes spécialisé pour les nombres
060
![Page 62: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/62.jpg)
Numpy: Array
additionsoustractionmultiplication par un scalaireproduit scalaire...
Rem. On ne mélange pas "mot" et nombre dans un array
061
![Page 63: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/63.jpg)
Linspace
Vecteur uniformément réparti entre [a,b] avec N échantillons
062
![Page 64: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/64.jpg)
AffichageCombinaison array + affichage
élève au carré élément à élément
063
![Page 65: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/65.jpg)
Array-range
arange: similaire à range
1 3 5 7
064
![Page 66: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/66.jpg)
Slicing
065
![Page 67: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/67.jpg)
Vecteurs particuliers
0 0 0 0 0
1 1 1 1 1 1
va
vb
066
![Page 68: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/68.jpg)
Embellissement graphique
067
![Page 69: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/69.jpg)
Courbe et points 3D
068
![Page 70: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/70.jpg)
Courbe et points 3D
069
![Page 71: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/71.jpg)
Matrices
070
![Page 72: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/72.jpg)
Matrices
071
![Page 73: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/73.jpg)
Matrices
Produit matriciel
072
![Page 74: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/74.jpg)
Matrices
Matrices carrées
073
![Page 75: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/75.jpg)
Matrices
Bloc/slicing
074
![Page 76: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/76.jpg)
Operateurs matriciels
linalg = linear algebra
075
![Page 77: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/77.jpg)
Algèbre linéaire
076
![Page 78: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/78.jpg)
Diagonalisation
077
![Page 79: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/79.jpg)
Affichage matrices/images
078
![Page 80: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/80.jpg)
Affichage matrices/images
079
![Page 81: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/81.jpg)
Affichage matrices/images
080
![Page 82: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/82.jpg)
Affichage fonctions 2D
081
![Page 83: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/83.jpg)
Affichage fonctions 2D
Soit:
Afficher f (utiliser la colormap "hot")
082
![Page 84: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/84.jpg)
Affichage fonctions 2DSoit:
Afficher f (utiliser la colormap "hot")
083
![Page 85: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/85.jpg)
Fichiers
084
![Page 86: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/86.jpg)
Lecture d'un fichier
Lecture ligne à ligne
085
![Page 87: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/87.jpg)
Traitement d'un texte
Maître Pelican, sur un arbre perché,Tenait en son bec un fromage.Maître Renard, par l'odeur alléché,Lui tint à peu près ce langage :"Hé ! bonjour, Monsieur du Pelican....
086
![Page 88: Introduction à la programmation Pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2. 22. · Cas particulier du test d'égalité symbole == test d'égalité a=b a==b](https://reader036.vdocuments.mx/reader036/viewer/2022071505/6125c64c751e977a387fb4db/html5/thumbnails/88.jpg)
Ecriture fichier
write/ecrit(supprime/créé un fichier vierge)
087