Alles samenbrengen

Introductie tot functies in Python

Hugo Bowne-Anderson

Instructor

Volgende oefeningen:

  • Gegeneraliseerde functies:

    • Tel voorkomens voor elke kolom

    • Tel voorkomens voor een willekeurig aantal kolommen

Introductie tot functies in Python

Voeg een standaardargument toe

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
Introductie tot functies in Python

Flexibele argumenten: *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
Introductie tot functies in Python

Laten we oefenen!

Introductie tot functies in Python

Preparing Video For Download...