Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
python:fonctions [2019/10/20 15:39] – créée physix | python:fonctions [2020/07/24 03:31] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Fonctions ====== | ====== Fonctions ====== | ||
+ | |||
+ | ===== Créer une fonction ===== | ||
+ | |||
+ | <code python> | ||
+ | def parabole(x): | ||
+ | return x ** 2 - 3 | ||
+ | |||
+ | </ | ||
+ | |||
+ | Ainsi la fonction " | ||
+ | |||
+ | Pour l' | ||
+ | |||
+ | <code python> | ||
+ | parabole(4) | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Importer une fonction ===== | ||
+ | |||
+ | <code python> | ||
+ | from math import cos, pi | ||
+ | |||
+ | print(pi) | ||
+ | |||
+ | print(cos( pi / 3. ) | ||
+ | |||
+ | </ | ||
+ | |||
+ | donne | ||
+ | |||
+ | <code python> | ||
+ | 3.141592653589793 | ||
+ | |||
+ | 0.5000000000000001 | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <code python> | ||
+ | import math | ||
+ | |||
+ | print(math.cos( math.pi / 3. )) | ||
+ | |||
+ | </ | ||
+ | |||
+ | donne | ||
+ | |||
+ | < | ||
+ | 0.5000000000000001 | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | <code python> | ||
+ | import math as m | ||
+ | |||
+ | print(m.cos ( m.pi / 3. )) | ||
+ | |||
+ | </ | ||
+ | |||
+ | donne | ||
+ | |||
+ | < | ||
+ | 0.5000000000000001 | ||
+ | |||
+ | </ | ||