Advertisement
teslariu

funcio

Oct 18th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. DOCSTRING:
  5. Script que demuestra como implementar
  6. funciones en python
  7. """
  8. '''
  9. def imprimir(lista =["Ja","Je","Ji"]):
  10.     """
  11.     funcion con keywords arguments
  12.     """
  13.     for elemento in lista:
  14.         print(elemento)
  15.        
  16.    
  17. numeros = [1,2,3,4,5,6,7,8]
  18. nombres = ["ana","tito","juan"]
  19.  
  20. imprimir(nombres)
  21. imprimir(numeros)
  22. imprimir()
  23.  
  24. print(help(imprimir))
  25.  
  26. def sumar(b,c,a=2):
  27.     return a+b+c
  28.    
  29. print(sumar(1,2,4))
  30. print(sumar(1,5))
  31.  
  32. # funciones lambda (o funciones inline o anónimas)
  33. sumar2 = lambda a,b: a+b
  34. print(sumar2(2,4))
  35. print(type(sumar2))
  36.  
  37. sumar2 = "Soy sumar 2"
  38. print(sumar2)
  39.  
  40. '''
  41. def sumar(a,b,c,d,e):
  42.     print(a+b+c+d+e)
  43.    
  44. n = [1,2,3,4,5]
  45.  
  46. # usando los indices
  47. sumar(n[0], n[1], n[2], n[3], n[4])
  48.  
  49. # usando el unpacking
  50. a,b,c,d,e = n
  51. sumar(a,b,c,d,e)
  52.  
  53. # usando agrupamiento y desagrupamiento
  54. sumar(*n)
  55.  
  56. def datos(clima,temp,hum):
  57.     print(f"""
  58.     **********************
  59.     Clima: {clima}
  60.     Temperatura: {temp}ºC
  61.     Humedad: {hum}%
  62.     **********************
  63.     """)
  64.    
  65. valores = {"clima":"Soleado", "temp":22, "hum":22}
  66. datos(**valores)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement