Parens do create a tuple

Steven D'Aprano steve at pearwood.info
Mon Apr 11 00:08:14 EDT 2016


On 2016年4月11日 12:51 pm, Random832 wrote:
> On Sun, Apr 10, 2016, at 22:32, Steven D'Aprano wrote:
>> def func(arg1, arg2, arg3):
>> pass
>>>> func(1, 2, 3)
>>>> does not create a tuple (1, 2, 3) anywhere in its execution.
>> Well, the second argument to PyObject_Call and function_call is a tuple,
> which had to come from somewhere.

It didn't come from any Python language feature. It is a purely internal
implementation detail.
Let me put it this way: a Python expression like 3/x-1 may be parsed into a
abstract syntax tree which might look something like this:
(OPERATOR, -, 
 (OPERATOR, /, 
 (CONSTANT, 3, None, None), 
 (NAME, 'x', None, None)), 
 (CONSTANT, 1, None, None)
 )
Should we say that the / and - operators therefore create tuples? I don't
think so.
-- 
Steven


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /