How to Use **kwargs in Python

preview_player
Показать описание
This video goes over the basics of using the **kwargs construction in Python to allow a function to take any number of named arguments.

Code used in this video is available in the comments below!
Рекомендации по теме
Комментарии
Автор

# Use **kwargs to pass any # of named arguments to a function
# **kwargs become a dictionary you can use in the function:

def print_kwargs(**kwargs):
print(kwargs)

print_kwargs(goku=9001, krillin=1500, piccolo=2500)

def extract_kwargs(**kwargs):

# Extract and print keys
print([*kwargs])
# Extract and print values
print([*kwargs.values()])

extract_kwargs(goku=9001, krillin=1500, piccolo=2500)

# Note that the "**" symbol is what is important
# "kwargs" could by anything!

def
print(kw_params)

other_word_for_kwargs(goku=9001, krillin=1500,
piccolo=2500, DataDaft=13839)

DataDaft
Автор

So underrated channel!!
Bro, ' please continue your amazing work!

antonborkovski
Автор

Hey! Thanks I was struggling to understand kwargs from Bro Codes tutorial but this helped me get the rest of the way!

coreygish
Автор

Well, that's educating. However, I've not seen any difference in using *args and **kwargs
Because, I interchanged them and the result is the same. Pls, if there's any difference in usage, enlighten me further. Thanks

funnyclips