How to do [1]*4 for a tuple

Vineet Jain vineet at eswap.com
Mon Apr 5 21:05:34 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. There are times when I
have to do the following:

'%s some value %s and some other text %s' % (a)*3

as apposed to

'%s some value %s and some other text %s' % (a, a, a)

In this case I always end up doing

'%s some value %s and some other text %s' % [a]*3

VJ





More information about the Python-list mailing list