Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

what is * in argument list in python

# It means that parameter(s) that comes after * are keyword only parameters.
# Consider the following:
def test(delay, result=None, *, loop=None):
    print(delay, result, loop)

'''
In this case, test(1,2,2) will raise TypeError since it is
expecting at most two positional arguments, i.e. delay and result:

test(1,2,2)
TypeError: test() takes from 1 to 2 positional arguments but 3 were given
'''

# The third argument, or loop, can only be assigned if used as keyword:
test(1,2,loop=2)
# 1 2 2
# Works fine
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #argument #list #python
ADD COMMENT
Topic
Name
3+3 =