How to do [1]*4 for a tuple

Tony Meyer t-meyer at ihug.co.nz
Mon Apr 5 21:10:31 EDT 2004


> I'm not sure I understand why [1]*4 and (1)*4 work differently? [1]*4
> results in [1, 1, 1, 1] while (1)*4 results in 4.

(1) isn't a tuple, it's a 1 in parentheses.

>>> (1) * 4
4
>>> (1,) * 4
(1, 1, 1, 1)

=Tony Meyer





More information about the Python-list mailing list