綜合運用

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...