Meaning of * in the function arguments list

2014-10-29 Thread ast

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 ?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Meaning of * in the function arguments list

2014-10-29 Thread Peter Otten
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


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Meaning of * in the function arguments list

2014-10-29 Thread ast


Peter Otten __pete...@web.de a écrit dans le message de 
news:mailman.15291.1414574006.18130.python-l...@python.org...


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



ok, thx 


--
https://mail.python.org/mailman/listinfo/python-list


Re: Meaning of * in the function arguments list

2014-10-29 Thread Terry Reedy

On 10/29/2014 4:56 AM, 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 ?


If you go to the online doc index page for Symbols,
https://docs.python.org/3/genindex-Symbols.html
there a 3 entries for the use of * as an operator, in statements (in 
particular, def for functions), and in function calls.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list