length of a tuple or a list containing only one element

alex23 wuwei23 at gmail.com
Mon Nov 3 06:14:32 EST 2008


On Nov 3, 9:08 pm, TP <Tribulati... at Paralleles.invalid> wrote:
> I have a question about the difference of behavior of "len" when applied on
> tuples or on lists. I mean:
> $ len( ( 'foo' ) )
> 3

This is actually the length of a bracketed string, not a tuple.
Tuple's are defined by the existence of a comma...try:

>>> len(('foo',))
1





More information about the Python-list mailing list