Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- DOCSTRING:
- Script que demuestra como implementar
- funciones en python
- """
- '''
- def imprimir(lista =["Ja","Je","Ji"]):
- """
- funcion con keywords arguments
- """
- for elemento in lista:
- print(elemento)
- numeros = [1,2,3,4,5,6,7,8]
- nombres = ["ana","tito","juan"]
- imprimir(nombres)
- imprimir(numeros)
- imprimir()
- print(help(imprimir))
- def sumar(b,c,a=2):
- return a+b+c
- print(sumar(1,2,4))
- print(sumar(1,5))
- # funciones lambda (o funciones inline o anónimas)
- sumar2 = lambda a,b: a+b
- print(sumar2(2,4))
- print(type(sumar2))
- sumar2 = "Soy sumar 2"
- print(sumar2)
- '''
- def sumar(a,b,c,d,e):
- print(a+b+c+d+e)
- n = [1,2,3,4,5]
- # usando los indices
- sumar(n[0], n[1], n[2], n[3], n[4])
- # usando el unpacking
- a,b,c,d,e = n
- sumar(a,b,c,d,e)
- # usando agrupamiento y desagrupamiento
- sumar(*n)
- def datos(clima,temp,hum):
- print(f"""
- **********************
- Clima: {clima}
- Temperatura: {temp}ºC
- Humedad: {hum}%
- **********************
- """)
- valores = {"clima":"Soleado", "temp":22, "hum":22}
- datos(**valores)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement