0

How does CPython, behind the scenes, evaluate expressions like

args = (2,3)
print(*args) 

?

The above obviously prints 2 3, but what is CPython doing to make that appear? . Thus can I think of the * operator applied to iterables as a kind of macro, that CPython when running simply replaces with the iterable contents?

NOTE TO ALL WHO WOULD LIKE TO MARK MY QUESTION IMMEDIATELY AS DUPLICATE (AS HAPPENED IN THE PAST): This question is not addressed by What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
That question addresses how * behaves in all kinds of scenarios - I'm not interested in knowing that.
There there is also only a single mentioning of CPython (which doesn't address my concern).

I want to know **internally* how CPython treats the code pasted above. Can I think of the * operator applied to iterables as a kind of macro, that CPython, when running, simply replaces with the iterable contents - or is CPython doing some more complex operation when parsing *args in the scenario above?

l7ll7
  • 1,309
  • 1
  • 10
  • 20
  • Possible duplicate of [Use of \*args and \*\*kwargs](https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs) – Corey Goldberg Dec 23 '18 at 13:56
  • Unsure of what you are really expecting, but I think that [PEP 448](https://www.python.org/dev/peps/pep-0448/) should bring some answers. For the rest, it cannot be a macro because Python has no macros, but is explicit in Python syntax:see 6.3.4 in [Python Language Reference](https://docs.python.org/3/reference/expressions.html#primaries) – Serge Ballesta Dec 23 '18 at 14:07

0 Answers0