Python **KWARGS?? #python #coding #programming

preview_player
Показать описание
This short video explains what **kwargs means in Python.

Background Music:
Creative Commons / Attribution 3.0 Unported License (CC BY 3.0)
Рекомендации по теме
Комментарии
Автор

kwargs is commonly used because it means "keyword arguments"

JayArnelBilocura
Автор

For those wondering why you would use this rather than just name the arguments, the most common example is if you write a function that itself calls a function. By using **kwargs, you can pass on any extra arguments to the inner function call automatically by adding **kwargs to the end of the function call. It allows caller function and called function to work together while being completely decoupled (i.e. you don't need to include all the arguments for the inner function in the signature of the outer function)

austinnar
Автор

Every time i learn something new about python makes me want to learn more

amrosamier
Автор

kwargs is basically a variable. The "**" basically turns the input into an object with key and value.

rosesunflow
Автор

Fantastic video. Rightly highlighted the difference of single and double asterisk. Wow!! Thanks so much dude

TheRealKitWalker
Автор

Last semester I had a class on python and the lecturer didn't give a straight answer on kwargs thank you I finally understand

gameknight
Автор

It's used in some specific scenarios. But when devs use this a lot, code becomes hard to debug or maintainable without really good docs

hazy
Автор

Seems like a great way to give someone else a headache

shaded
Автор

TFW you've been a profession python dev for nearly 15 years now, but you still watch these videos because you're self taught and the imposter syndrome is STRONG.

reikoshea
Автор

Just pointing out that 3*1+2=5 as does 1*2+3=5 so, whilst it is a great video (thanks for all of the content), maybe choose examples that don't use 1 as a multiplier😅

myleslloyd
Автор

Thank u so much sir, it actually helped me a lot 🥰

kainime
Автор

It would have worked anyway with def func(a, b, c)

Ht-
Автор

My only complaint about *args and **kwargs is that it obscures the arguments the methods could take. Make sure to write good docstrings if you do use them.

Kylemsguy
Автор

This little short told me more then a few lectures...

TheAjon
Автор

This is kinda cool and scary at the same time

tommasochiti
Автор

you know what's cool? You can also used the operator in reverse. func(**{'a':1, 'b':2, 'c':3}) is also valid. same goes for single astrix by the way

func(*[1, 2, 3], **{'a':1, 'b':2, 'c':3}) would do the same as func(1, 2, 3, a=1, b=2, c=3)

nobodyofconsequence
Автор

In cases like this I just can't see the benefit of just having one parameter that gets used like a dict if you can just have the parameters a, b and c in the function directly. It just makes it less safe since it gives no hint to the developer that has to use this what parameters are needed.
There are reasons for these kwargs but I would only use them for optional parameters and even then in most cases I would use normal parameters with a default value.

What I'm trying to say is, if you use them be sure to check if they are actually set and for god's sake, DOCUMENT THEIR EXISTENCE.

That being said I like your videos :)

omgky
Автор

Got the idea, but addition anyway would be same because of commutative law of addition.

fishsauce
Автор

The commutative properties of addition doesn't do much to prove the functionality, but i see what he's saying.

cborbon
Автор

It resembles the spread operator in JS but only for function arguments

kirarevcrow
visit shbcf.ru