Funções

Introdução ao Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Funções

  • Nada de novo!

  • type()

  • Código reutilizável

  • Resolve uma tarefa específica

  • Chamar uma função em vez de escrever o código por conta própria

Introdução ao Python

Exemplo

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.012.png

Introdução ao Python

Exemplo

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.013.png

Introdução ao Python

Exemplo

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.014.png

Introdução ao Python

Exemplo

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89
tallest = max(fam)
tallest
1.89
Introdução ao Python

round()

round(1.68, 1)
1.7
round(1.68)
2
help(round) # Open up documentation
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative.
Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.026.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.027.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.028.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.029.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.030.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.031.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.032.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.033.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.034.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.035.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.036.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.037.png

Introdução ao Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 
  • round(number)
  • round(number, ndigits)
Introdução ao Python

Como encontrar funções

  • Como saber?

  • Tarefa padrão -> provavelmente existe uma função!

  • A internet é sua aliada

Introdução ao Python

Vamos praticar!

Introdução ao Python

Preparing Video For Download...