Type(3,) returns an integer instead of a tuple in python, why?

python, tuples, types

Solution

Inside the parentheses that form the function call operator, the comma is not for building tuples, but for separating arguments. Thus, `type(3, )` is equivalent to `type(3)`. An additional comma at the end of the argument list is allowed by the grammar. You need an extra pair of parens to build a tuple:

>>> def f(x):
...     print x
... 
>>> f(3)
3
>>> f(3,)
3
>>> f((3,))
(3,)

Problem

`type(3,)` returns the int type, while ``` t = 3, type(t) ``` returns the tuple type. Why?

Original source