Tổng hợp lại

Giới thiệu về Functions trong Python

Hugo Bowne-Anderson

Instructor

Bài tập tiếp theo:

  • Hàm tổng quát:

    • Đếm số lần xuất hiện cho bất kỳ cột nào

    • Đếm số lần xuất hiện cho số cột bất kỳ

Giới thiệu về Functions trong Python

Thêm đối số mặc định

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
Giới thiệu về Functions trong Python

Đối số linh hoạt: *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
Giới thiệu về Functions trong Python

Hãy luyện tập!

Giới thiệu về Functions trong Python

Preparing Video For Download...