maybe a bug in python
Steve Horsley
steve.horsley at gmail.com
Sun Jun 5 13:00:08 EDT 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
somewhere.
The comma eliminates ambiguity as to the meaning of the brackets,
which without the comma are simply enclosing and precedence
controlling brackets.
Steve
More information about the Python-list
mailing list