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, because otherwise it
gives an error:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
'first={0}, last={1}, middle={2}'.format(parts)
IndexError: tuple index out of range
Still, wouldn't python basically see 'parts' and insert the actual tuple
instead of the variable 'parts'? How does the machine think?
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor