python:fonctions

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
python:fonctions [2019/10/20 15:49] physixpython:fonctions [2020/07/24 03:31] (Version actuelle) – modification externe 127.0.0.1
Ligne 1: Ligne 1:
 ====== Fonctions ====== ====== Fonctions ======
  
-<code>+===== Créer une fonction ===== 
 + 
 +<code python>
 def parabole(x): def parabole(x):
     return x ** 2 - 3     return x ** 2 - 3
Ligne 11: Ligne 13:
 Pour l'utiliser, il suffit de taper parabole et un argument entre parenthèses. Cet argument sera affecté à la variable x de la définition de la fonction. Cette fonction renverra alors le résultat. Pour l'utiliser, il suffit de taper parabole et un argument entre parenthèses. Cet argument sera affecté à la variable x de la définition de la fonction. Cette fonction renverra alors le résultat.
  
-<code>+<code python>
 parabole(4) parabole(4)
 +
 +</code>
 +
 +===== Importer une fonction =====
 +
 +<code python>
 +from math import cos, pi
 +
 +print(pi)
 +
 +print(cos( pi / 3. )
 +
 +</code>
 +
 +donne
 +
 +<code python>
 +3.141592653589793
 +
 +0.5000000000000001
 +
 +</code>
 +
 +----
 +
 +<code python>
 +import math
 +
 +print(math.cos( math.pi / 3. ))
 +
 +</code>
 +
 +donne
 +
 +<code>
 +0.5000000000000001
 +
 +</code>
 +
 +
 +
 +<code python>
 +import math as m
 +
 +print(m.cos ( m.pi / 3. ))
 +
 +</code>
 +
 +donne
 +
 +<code>
 +0.5000000000000001
  
 </code> </code>
  
  
  • python/fonctions.1571579367.txt.gz
  • Dernière modification : 2020/07/24 00:23
  • (modification externe)