Advertisement
teslariu

func propias2

Nov 11th, 2022
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # FUNCIONES PROPIAS CON ARGUMENTOS DE LONG. VARIABLE
  5.  
  6. def sumar(*args):
  7.     total = 0
  8.     for n in args:
  9.         total += n
  10.     return total
  11.    
  12.    
  13. print(sumar(1,2,3))
  14.  
  15.  
  16.  
  17.  
  18. def sumar2(**kwargs):
  19.     total = 0
  20.     for n in kwargs:
  21.         total += kwargs[n]
  22.     return total
  23.  
  24. print(sumar2(a=12, b=152, c=140, d=100, e=14, f=-418))
  25.  
  26. # orden para usar dif argumentos
  27. def f(a, b, *args, c=999, **kwargs):
  28.     print(a)
  29.     print(b)
  30.     print(args)
  31.     print(c)
  32.     print(kwargs)
  33.    
  34.    
  35. f(1,2,100,200,300,400,c=4,x=23,y=2,z=21)
  36.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement