Fonctions

Introduction à Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Fonctions

  • Rien de nouveau !

  • type()

  • Morceau de code réutilisable

  • Résout une tâche spécifique

  • Utilisez une fonction plutôt que d'écrire du code vous-même

Introduction à Python

Exemple

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.012.png

Introduction à Python

Exemple

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.013.png

Introduction à Python

Exemple

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.014.png

Introduction à Python

Exemple

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89
tallest = max(fam)
tallest
1.89
Introduction à Python

round()

round(1.68, 1)
1.7
round(1.68)
2
help(round) # Open up documentation
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative.
Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.026.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.027.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.028.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.029.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.030.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.031.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.032.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.033.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.034.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.035.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.036.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.037.png

Introduction à Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 
  • round(number)
  • round(number, ndigits)
Introduction à Python

Rechercher des fonctions

  • Comment le savoir ?

  • Tâche standard -> la fonction existe probablement !

  • Internet est votre allié

Introduction à Python

Passons à la pratique !

Introduction à Python

Preparing Video For Download...