Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what is ,*, ?
#11
(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 Confused

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
Reply


Messages In This Thread
what is ,*, ? - by Skaperen - Sep-09-2017, 01:45 AM
RE: what is ,*, ? - by metulburr - Sep-09-2017, 01:57 AM
RE: what is ,*, ? - by ichabod801 - Sep-09-2017, 02:27 AM
RE: what is ,*, ? - by Skaperen - Sep-09-2017, 04:02 AM
RE: what is ,*, ? - by hbknjr - Sep-09-2017, 07:24 AM
RE: what is ,*, ? - by syogun - Sep-09-2017, 12:26 PM
RE: what is ,*, ? - by Skaperen - Sep-10-2017, 12:23 AM
RE: what is ,*, ? - by metulburr - Sep-09-2017, 10:00 PM
RE: what is ,*, ? - by dvs1 - Sep-09-2017, 10:54 PM
RE: what is ,*, ? - by Larz60+ - Sep-09-2017, 11:03 PM
RE: what is ,*, ? - by Skaperen - Sep-10-2017, 02:56 AM
RE: what is ,*, ? - by snippsat - Sep-10-2017, 12:39 AM
RE: what is ,*, ? - by snippsat - Sep-10-2017, 01:00 AM
RE: what is ,*, ? - by Larz60+ - Sep-10-2017, 01:50 AM
RE: what is ,*, ? - by ichabod801 - Sep-10-2017, 02:09 AM
RE: what is ,*, ? - by syogun - Sep-10-2017, 02:15 AM
RE: what is ,*, ? - by metulburr - Sep-10-2017, 04:05 AM
RE: what is ,*, ? - by syogun - Sep-10-2017, 04:40 AM
RE: what is ,*, ? - by ichabod801 - Sep-10-2017, 01:03 PM
RE: what is ,*, ? - by metulburr - Sep-10-2017, 10:35 PM
RE: what is ,*, ? - by nilamo - Sep-10-2017, 11:20 PM
RE: what is ,*, ? - by Skaperen - Sep-11-2017, 01:24 AM
RE: what is ,*, ? - by Skaperen - Sep-11-2017, 03:19 AM
RE: what is ,*, ? - by Sagar - Sep-11-2017, 09:13 AM
RE: what is ,*, ? - by Skaperen - Sep-13-2017, 01:07 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020