maybe a bug in python

venkata subramanian venkatasubramanian at gmail.com
Mon Jun 6 12:17:52 EDT 2005


If you have any doubts,
try to remeber this when creating tuples,

if a tuple is to have 0 elements,
then it must be given as a=() 
in other words, the ( and the ) are essential

if it has one element,
then a comma after that element is essential
a=1,
or alternatively
a=(1,)
in other words, an end comma is essential but the parentheses are not

if it has more than one element, comma between the elements is only essential
a=1,2
or alternatively
a=1,2,
or alternatively
a=(1,2)

i might have made some silly mistake.... so wait till some one points
it out (if the mistakes are there) :)



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