Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what is ,*, ?
#24
I have written a code to understand the use of bare "*" in function argument list and I am sharing that with everyone.

I have created a function called myFunction having three arguments "a","b" and "c". I placed "*" between a and b
def myFunction(a,*,b,c):
	print('a',a)
	print('b',b)
	print('c',c)

myFunction(10,c=20,b=12)
Output:
Output:
a 10 b 12 c 20
The "*" in argument list of a function ensures that the arguments after that are Non-positional
Non-positional argument means that the order of that argument during function call is not fixed and value is passed using key of that argument.
The arguments before * are positional arguments and values are passed to these argument without keys.

Another code:
def myFunction(*,a,b,c):
	print('a',a)
	print('b',b)
	print('c',c)

myFunction(a=10,c=20,b=12)
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