総まとめ

Pythonの関数入門

Hugo Bowne-Anderson

Instructor

次の演習:

  • 汎用関数:

    • 任意の列の出現回数を数える

    • 複数列の出現回数を数える

Pythonの関数入門

デフォルト引数を追加する

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
Pythonの関数入門

可変長引数: *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
Pythonの関数入門

演習しましょう!

Pythonの関数入門

Preparing Video For Download...