Equivalent 2->> print '%d %d' %(l[i], for i in range(2))?

Doug Stanfield DOUGS at oceanic.com
Thu May 17 11:42:27 EDT 2001


[Jorn Verwey ]
> How can I avoid typing %(l[0],l[1]) in the following case?
> ->> l=[4,14]
> ->> print '%d %d' %(l[0],l[1])

String interpolation wants a tuple so how about:

Python 1.5.2 (#1, Apr 18 1999, 16:03:16)  [GCC pgcc-2.91.60 19981201
(egcs-1.1.1  on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> l=[4,14]
>>> print '%d %d' % tuple(l[:2])
4 14

-Doug-




More information about the Python-list mailing list