wrote
'first={0}, last={1}, middle={2}'.format(*parts)
"first=S, last=M, middle=['P', 'A']"
why do we need the '*' at 'parts'. I know we need it, because
otherwise it
gives an error:
The * tells Python to unpack parts and treat the contents
as individual values. format is looking for 3 v
I see now, that example helps. Basically I use one asterisk to extract a
list or a tuple and double asterisks for a dictionary, but I have to provide
keys in case of a dictionary, like here:
>>> template = '{motto}, {pork} and {food}'
>>> a = dict(motto='spam', pork='ham', food='eggs')
>>> templat
From: tutor-bounces+ramit.prasad=jpmchase@python.org
[mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of
eize...@gmail.com
Sent: Wednesday, June 08, 2011 3:11 PM
To: tutor@python.org
Subject: [Tutor] String formatting question with 's'.format()
I'm work
I'm working through the 'Learn Python' book by Mark Lutz, in this example:
somelist = list('SPAM')
parts = somelist[0], somelist[-1], somelist[1:3]
'first={0}, last={1}, middle={2}'.format(*parts)
"first=S, last=M, middle=['P', 'A']"
why do we need the '*' at 'parts'. I know we need it, becaus