Juntando tudo

Introdução a Funções em Python

Hugo Bowne-Anderson

Instructor

Próximos exercícios:

  • Funções generalizadas:

    • Contar ocorrências de qualquer coluna

    • Contar ocorrências de um número arbitrário de colunas

Introdução a Funções em Python

Adicionar um argumento padrão

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
Introdução a Funções em Python

Argumentos flexíveis: *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
Introdução a Funções em Python

Vamos praticar!

Introdução a Funções em Python

Preparing Video For Download...