Question about tuple lengths

Larry Bates larry.bates at websafe.com
Thu Dec 15 19:31:33 CET 2005


Carl J. Van Arsdall wrote:
> 
> From my interpreter prompt:
> 
>>>> tuple = ("blah")
>>>> len(tuple)
> 4
>>>> tuple2 = ("blah",)
>>>> len (tuple2)
> 1
> 
> 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?

Additional note:

You should not give a tuple a variable name of tuple, it masks
the built-in tuple() function.  This also goes for str, or other
built-ins.  This will "bite" you at some point if it hasn't already.

-Larry Bates



More information about the Python-list mailing list