Académique Documents
Professionnel Documents
Culture Documents
04
✔ AIDE MEMOIRE, GESTION DES ERREURS: NSI
SYNTAXE DES DECLARATIONS ET APPELS DE FONCTIONS
def ma_fonction():
QUELQUES TYPES D´ERREURS Déclaration et appel d´une fonction sans instructions
argument en entrée ni valeur retournée
Type d´erreur : exemples: en sortie (on parle de procédure). # appel:
ma_fonction()
ValueError
>>> int("NSI")
Déclaration et appel d´une fonction sans def ma_fonction():
argument en entrée avec valeur instructions
retournée en sortie. return variable
>>> from math import * ma_fonction() est maintenant une # appel:
variable de type int, float, str, bool... ma_fonction()
>>> sqrt(-4)
Déclaration d´une autre fonction avec def ma_fonction(arg1,arg2,arg3,..):
ZeroDivisionError arguments (arg) en entrée puis appel instructions
>>> 10/0 avec paramètres (param) return variable
correspondants.
# appel:
TypeError >>> "3" + 3 Les paramètres et arguments peuvent ma_fonction(param1,param2,param3,..)
être de type int, float, str, bool..
LES FONCTIONS