Question about tuple lengths
mmzeeman at xs4all.nl
Wed Dec 14 20:57:14 CET 2005
Carl J. Van Arsdall wrote:
> From my interpreter prompt:
> >>> tuple = ("blah")
> >>> len(tuple)
> >>> tuple2 = ("blah",)
> >>> len (tuple2)
> So why is a tuple containing the string "blah" without the comma of
> length four? Is there a good reason for this or is this a bug?
Thats because the expression ("blah") actually resolves to "blah" instead of
a tuple containing the string "blah".
Adding a comma after spam results in the tuple being created.
And to make things even more confusing, just adding a comma without braces
will give you a tuple too.
The explanation for this all can be found at:
More information about the Python-list