0

Why type((1)) is int and not a tuple? Whereas type((1,)) gives tuple.

unknown29
  • 47
  • 5

2 Answers2

1

That's also an answer to the question why we should use commas while defining a tuple with one value. Because tuples are not like lists which is unique in a way that we define it (using squared brackets) we have to add the comma to the value. In the first one type((1)) inner paranthesis have no effect, so it's just a basic integer nothing else. Like when you define expressions in paranthesis to give them priority. Hope it helps :)

0

Python compiler treated (1) as 1 because of that it is showing as int. that is inbuilt behavior of python compiler.

>>> a = (1)
>>> print(a)
1
>>> a = (1,)
>>> print(a)
(1,)
Vicrobot
  • 3,795
  • 1
  • 17
  • 31
dine b
  • 39
  • 3