Funciones

Introducción a Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Funciones

  • ¡Nada nuevo!

  • type()

  • Fragmento de código reutilizable

  • Resuelve una tarea concreta.

  • Llama a la función en lugar de escribir el código tú mismo.

Introducción a Python

Ejemplo

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

Introducción a Python

Ejemplo

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

Introducción a Python

Ejemplo

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

Introducción a Python

Ejemplo

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
Introducción a 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.
Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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

Introducción a 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)
Introducción a Python

Buscar funciones

  • ¿Cómo saberlo?

  • Tarea estándar -> ¡probablemente exista una función!

  • Internet es tu amigo.

Introducción a Python

¡Vamos a practicar!

Introducción a Python

Preparing Video For Download...