Advertisement
teslariu

func

Nov 6th, 2021
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. def suma(a,b,c,d,e):
  6.     return a+b+c+d+e
  7.    
  8. args = [1,2,3,4,5]
  9. kwargs = {"a":1, "b":2, "c":3, "d":4, "e":5}
  10.  
  11.  
  12.  
  13. # Forma fea
  14. total = suma(args[0], args[1], args[2], args[3], args[4])
  15. print(total)
  16.  
  17. # Forma "mas mejor" (unpacking)
  18. a,b,c,d,e = args
  19. total = suma(a,b,c,d,e)
  20. print(total)
  21.  
  22. # forma óptima (desagrupamiento)
  23. total = suma(*args)
  24. print(total)
  25.  
  26. # desagrupamiento con diccionario
  27. total = suma(**kwargs)
  28. print(total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement