Originally Posted by
IAMTubby
You mean to say
a = (1) is same as doing int a = 1;
whereas a=(1,) is like int a[] = {1};
If my above understanding is correct, then it makes sense. I shall mark the thread as solved after I get confirmation on this.
Yes, that's about it.
Hopefully, I'm not dragging this thread too long. But couldn't this have been avoided if a=1;(in python) was enough for int a = 1,(in C) and
a=(1) was an array(here tuple) ?
But I know very little python, and I'm sure there must be some reasoning to it.
Python, in common with many many languages (and math) allows parentheses to be placed around any expression. So we might write for example
Code:
>>> a = (((2) + (2)) * (6))
>>> print(a)
24
But a more natural way to write the same thing would be
Code:
>>> a = (2 + 2) * 6
>>> print(a)
24
We could simply that still further...
Code:
>>> a = (4) * 6
>>> print(a)
24
But by your suggestion, you don't want it to do that, because you want (4) to be a tuple, so you want it to be the same as
Code:
>>> a = (4,) * 6
>>> print(a)
(4, 4, 4, 4, 4, 4)
I suggest that would be somewhat confusing.
Bookmarks