[Tutor] multiple assignment

Vincent Gulinao vincent.gulinao at gmail.com
Tue Oct 18 07:10:49 CEST 2005

I was fascinated when I learned that I can do this in Python:

(str1, str2, str3, rest) = str.split(" ", 3)

Later that I realize that str could contain values of less than 4 strings,
in which case it would complain something like -- ValueError: unpack list of
wrong size.

Now I don't want to spoil the fun.

In essence, I'd like to capture the first 3 words in a string. If str is
less than 3 words then any or all of the containers could have a None value.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051018/c02245dd/attachment.html

More information about the Tutor mailing list