Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79901

Re: Meaning of * in the function arguments list

From Peter Otten <__peter__@web.de>
Subject Re: Meaning of * in the function arguments list
Date 2014-10-29 10:13 +0100
Organization None
References <5450ac05$0$21640$426a74cc@news.free.fr>
Newsgroups comp.lang.python
Message-ID <mailman.15291.1414574006.18130.python-list@python.org> (permalink)

Show all headers | View raw


ast wrote:

> Consider the following to_bytes method from integer class:
> 
> int.to_bytes(length, byteorder, *, signed=False)
> 
> What doest the '*' in the arguments list means ?

A bare * indicates that the arguments that follow it are keyword-only:

>>> def f(a, b=2, *, c=3):
...     print("a = {}, b = {}, c = {}".format(a, b, c))
... 
>>> f(10)
a = 10, b = 2, c = 3
>>> f(10, 20)
a = 10, b = 20, c = 3
>>> f(10, 20, 30)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() takes from 1 to 2 positional arguments but 3 were given
>>> f(10, 20, c=30)
a = 10, b = 20, c = 30

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Meaning of * in the function arguments list "ast" <nomail@invalid.com> - 2014-10-29 09:56 +0100
  Re: Meaning of * in the function arguments list Peter Otten <__peter__@web.de> - 2014-10-29 10:13 +0100
    Re: Meaning of * in the function arguments list "ast" <nomail@invalid.com> - 2014-10-29 10:37 +0100

csiph-web