introduction à la programmation pythonimagine.inrialpes.fr/.../cours/cours_python.pdf · 2014. 2....

88
Introduction à la programmation Python 000

Upload: others

Post on 31-Mar-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

+ 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

+ 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

+ 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Ecriture fichier

write/ecrit(supprime/créé un fichier vierge)

087