List vs. Tuple

Charles G Waldman cgw at fnal.gov
Thu Oct 7 11:57:54 EDT 1999


Matthew Hirsch writes:

 > Can someone explain to me why if there is only a string in a list/tuple
 > they behave differently when looped through.  For example,
 > 
 > >>> list=['abcd']
 > >>> tuple=('abcd')

Despite the name, "tuple" is not a tuple.  It's a string.  Parentheses 
are (unfortunately, IMO) overloaded, being both tuple-delimiters and
the standard grouping operator,  e.g. x=(1+3)*5

If you want to make a one-tuple, you need to use the following
slightly strange-looking construction:

  tuple = ('abcd',)





More information about the Python-list mailing list