Podsumowanie

Wprowadzenie do funkcji w Pythonie

Hugo Bowne-Anderson

Instructor

Następne ćwiczenia:

  • Funkcje ogólne:

    • Liczenie wystąpień dla dowolnej kolumny

    • Liczenie wystąpień dla dowolnej liczby kolumn

Wprowadzenie do funkcji w Pythonie

Dodawanie domyślnego argumentu

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
Wprowadzenie do funkcji w Pythonie

Elastyczne argumenty: *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
Wprowadzenie do funkcji w Pythonie

Czas na ćwiczenia!

Wprowadzenie do funkcji w Pythonie

Preparing Video For Download...