모두 종합하기

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