Puzzling difference between lists and tuples
William Pearson
william.pearson at gmail.com
Thu Sep 17 11:24:57 EDT 2020
I am puzzled by the reason for this difference between lists and tuples.
A list of with multiple strings can be reduced to a list with one string with the expected results:
for n in ['first','second']:
print n
for n in ['first']:
print n
The first loop prints "first", "second", and the second prints "first".
====
This is not true for a tuple:
for n in ('first','second'):
print n
for n in ('first'):
print n
prints "first", "second" in the first case, but "f","i","r","s","t" in the second.
Where is this inconsistency explained?
More information about the Python-list
mailing list