Python shows different data type for seemingly similar inputs.
While assigning a value to a variable like this, I get a tuple:
>>> x = 1,
>>> type(x)
>>> <class 'tuple'>
However when I do the same thing in the following way, it shows a different data type:
>>> type(1,)
>>> <class 'int'>
How and why do these two differ from each other?
Hello @thrasys
When you put a comma after 1 you have created a tuple with one item only.
So x is a tuple in your example
For more info read: Create Tuple With One Item
The other: type(1,)
I cannot explain.
Google and Youtube is useful.
PSA: I’m shutting down this forum so please direct future help requests to the Discord or help@learncodethehardway.com.