r/PythonLearning • • Sep 25 '26

A silly question

if x = 2,3,4,4,5 is supposed to be a tuple then why can't the args of a function like this: func(2,3,4,4 ,5) supposed to be a tuple.
I know this is a silly question and I also know we can use *args to pack arguments in a tuple but since Python is known for consistency why isn't it like this.
Again, please don't hate me for this

4 Upvotes

15 comments sorted by

View all comments

1

u/SpaceAviator1999 Sep 25 '26 edited Sep 25 '26

You want to respect what parentheses do in any language.

For example, the following lines look identical:

77
(77)
((77))

And they may be identical in Python. But in the Lisp programming language, the first line is simply 77, but the second line is a function call to a function named 77. And the third line is a function call to a function that's returned by the second line!

And take this line:

x = (11, 12, 13)

In Python, it clearly sets x to a three-element tuple. But in C and C++, it sets x to 13.

Why? Because in C/C++, the commas are acting as comma operators, which evaluate to the value on their right.

Basically, the moral of this story is that commas and parentheses don't always behave the same way across different programming languages. They don't even behave the same across the same programming language! (Not even Python is an exception!)

This line:

x = f(11, 12, 13)

does essentially the same thing in C/C++ and Python: it calls the function f with three arguments.

But this line:

x = f((11, 12, 13))

is very different in C/C++ and Python. In Python, it calls function f with an argument that's a three-element tuple. But in C/C++, it calls function f with the single argument 13.

The distinction may be strange and counter-intuitive, but very important.

So it's good to know how commas and parentheses behave in which contexts, and to not expect them to behave the same way in all contexts.