Couldn't find a unified resource that documents/explains this. I'm puzzled; is it an operator or not? Most importantly, what is its precedence? An example:
import functools
def array_sum(array):
return functools.reduce(lambda acc, curr: acc + curr, array)
print(array_sum([1,2])) # 3
# https://docs.python.org/3/reference/expressions.html#operator-precedence tells us that lambda has the lowest precedence.
# But the above code works, which means the comma gets applied after the lambda expression.
# If the comma was applied first, that would give us this runtime error: TypeError: reduce expected at least 2 arguments, got 1
Note that the comma isn't even listed as an operator in the link in the code comments. But here it is called an operator: https://docs.python.org/3/reference/expressions.html#parenthesized-forms
Python version: 3.7.4
EDIT:
I had originally provided this as an additional but incorrect example:
x = 4 if False else 3, 2
print(x) # (3,2)
x = 4 if True else 3, 2
print(x) # 4
# comma was applied before assignment operator
x, y = 4 if True else 3, 2
print(x) # 4
print(y) # 2
# comma was applied after assignment operator
But that was my mistake, because
x = 4 if True else 3, 2
print(x) # 4
was incorrect, and after running it again I saw that when corrected it is:
x = 4 if True else 3, 2
print(x) # (4, 2)
Therefore the comma precedence is behaving consistently in the example that was removed in the edit.
x = 4 if True else 3, 2andx, y = 4 if True else 3, 2act differently. I would have assumed the latter would have given an error because the RHS would evaluate to a single, non-iterable value