“Args y Kwargs” Código de respuesta

Uso de Kwargs y Args en clases de Python

def myFun(*args,**kwargs): 
    print("args: ", args) 
    print("kwargs: ", kwargs) 
    
myFun('my','name','is Maheep',firstname="Maheep",lastname="Chaudhary")

# *args - take the any number of argument as values from the user 
# **kwargs - take any number of arguments as key as keywords with 
# value associated with them
Open Osprey

Args y Kwargs

def adder(*num):
    sum = 0
    
    for n in num:
        sum = sum + n

    print("Sum:",sum)

adder(3,5)
adder(4,5,6,7)
adder(1,2,3,5,6)
Xerothermic Xenomorph

*Kwargs


# Python program to illustrate 
# *kwargs for variable number of keyword arguments
 
def myFun(**kwargs):
    for key, value in kwargs.items():
        print ("%s == %s" %(key, value))
 
# Driver code
myFun(first ='Geeks', mid ='for', last='Geeks') 

''' output: 
last == Geeks
mid == for
first == Geeks
'''
Harsha Narayana

Respuestas similares a “Args y Kwargs”

Preguntas similares a “Args y Kwargs”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código