maybe a bug in python

Steve Horsley steve.horsley at
Sun Jun 5 19:00:08 CEST 2005

flyaflya wrote:
>  >>> a = {1: ("a")}
>  >>> a[1]
> 'a'
> why not ('a')? when
>  >>> a = {1: ((("a")))}
>  >>> a[1]
> 'a'
> the result is 'a' too,not ((("a"))).but when use["a"] or ("a","b"),the 
> tuple is longer than 1, it's no problem.

To define a tuple literal with one member, you must place a comma 
after the first element like this:

a = {1: ("a",)}

I read this somewhere in the python docs, so I know its there 

The comma eliminates ambiguity as to the meaning of the brackets, 
which without the comma are simply enclosing and precedence 
controlling brackets.


More information about the Python-list mailing list