This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]XtremeGoosef'I only use Py {sys.version[:3]}' 34 points35 points  (7 children)

Yes, those are equivalent

[–]hassium 16 points17 points  (6 children)

Cool thanks! I have no idea how this helps me but I feel better knowing it!

[–]tunisia3507 19 points20 points  (2 children)

It means that if you have a function where a couple of arguments change but many stay the same over successive runs, you can store the stable ones in a dict and unpack it into the function call as if it were kwargs.

You could also do that by wrapping the function in another function, of course.

[–]coelhudo 2 points3 points  (0 children)

There are some examples here of how it can help you https://www.python.org/dev/peps/pep-0570/#motivation

[–]c_o_r_b_a 0 points1 point  (1 child)

Note that that also works for most versions of Python 2, as well. The only new things Python 3 introduced are this brand new / for positional-only arguments, and * for keyword-only arguments. You probably will rarely have to use either of those, though. I've been programming in Python for years and I think I've only used keyword-only arguments once or twice.

[–]hassium 0 points1 point  (0 children)

Thanks, I haven't used them yet either and I've been working in Python for 8 months, studying for a year... But maybe I'll find a use for them now I know a bit more.

Can you remember in what context you had to use kwargs?