Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79900 > unrolled thread
| Started by | "ast" <nomail@invalid.com> |
|---|---|
| First post | 2014-10-29 09:56 +0100 |
| Last post | 2014-10-29 10:37 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | "ast" <nomail@invalid.com> |
|---|---|
| Date | 2014-10-29 09:56 +0100 |
| Subject | Meaning of * in the function arguments list |
| Message-ID | <5450ac05$0$21640$426a74cc@news.free.fr> |
Hi Consider the following to_bytes method from integer class: int.to_bytes(length, byteorder, *, signed=False) What doest the '*' in the arguments list means ?
[toc] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-10-29 10:13 +0100 |
| Message-ID | <mailman.15291.1414574006.18130.python-list@python.org> |
| In reply to | #79900 |
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
[toc] | [prev] | [next] | [standalone]
| From | "ast" <nomail@invalid.com> |
|---|---|
| Date | 2014-10-29 10:37 +0100 |
| Message-ID | <5450b574$0$2908$426a74cc@news.free.fr> |
| In reply to | #79901 |
"Peter Otten" <__peter__@web.de> a écrit dans le message de news:mailman.15291.1414574006.18130.python-list@python.org... > > A bare * indicates that the arguments that follow it are keyword-only: > ok, thx
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web