Sep-10-2017, 12:39 AM
(Sep-09-2017, 11:03 PM)Larz60+ Wrote: It looks like the name of the function is automatically passed as argument b:No,default argument
test
is passed.Name of function is
test2
The point is as dvs1 showed.
If use that function without
,*,
,and pass in 2 positional argument.def test1(a, b='test'): print(a) print(b test1('hello', 'world')
Output:hello
world
So is allowed to give a argument that is not a keyword argumet.With
,*,
def test1(a,*, b='test'): print(a) print(b) test1('hello', 'world')
Output:Traceback (most recent call last):
File "e:\1py_div\div_code\pos.py", line 32, in <module>
test1('hello', 'world')
TypeError: test1() takes 1 positional argument but 2 were given
So is forced to use keyword argument.def test1(a,*, b='test'): print(a) print(b) test1('hello', b='world')
Output:hello
world