Récapitulatif

Introduction aux fonctions en Python

Hugo Bowne-Anderson

Instructor

Exercices suivants :

  • Fonctions généralisées :

    • Compter le nombre d'occurrences pour n'importe quelle colonne

    • Compter le nombre d'occurrences pour un nombre arbitraire de colonnes

Introduction aux fonctions en Python

Ajouter un argument par défaut

def power(number, pow=1):
    """Raise number to the power of pow."""
    new_value = number ** pow
    return new_value
power(9, 2)
81
power(9)
9
Introduction aux fonctions en Python

Arguments flexibles : *args (1)

def add_all(*args):
    """Sum all values in *args together."""

    # Initialize sum
    sum_all = 0

    # Accumulate the sum
    for num in args:
        sum_all = sum_all + num

    return sum_all
Introduction aux fonctions en Python

Passons à la pratique !

Introduction aux fonctions en Python

Preparing Video For Download...