0 votes
1 view
in Python by (12.7k points)

How is "Keyword Arguments" not quite the same as regular arguments? Can't all contentions be passed as name=value as opposed to utilizing positional syntax?

1 Answer

0 votes
by (26.4k points)

There are two related ideas, both are called "keyword arguments". 

On the calling side, which is the thing that other analysts have referenced, you can indicate some function contentions by name. You need to specify them after the entirety of the arguments without names (positional arguments), and there should be default esteems for any parameters which were not referenced whatsoever. 

The other idea is on the function definition side: you can characterize a function that takes boundaries by name - and you don't need to determine what those names are. These are actually pure keyword arguments, and can't be passed positionally. The punctuation is 

def my_function(arg1, arg2, **kwargs)

Any watchword contentions you pass into this function will be put into a word reference named kwargs. You can inspect the keys of this word reference at run-time, this way:

def my_function(**kwargs):

    print str(kwargs)

my_function(a=12, b="abc")

{'a': 12, 'b': 'abc'}

Join the python online course fast, to learn python concepts in detail and get certified.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Sep 25, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...