June 2017
Beginner
352 pages
8h 39m
English
We can then split strings up again using the split() method (which we've already encountered, but this time we're going to provide it's optional argument):
>>> colors.split(';')['#45ff23', '#2321FA', '#1298A3', '#A32912']
The optional argument lets you specify the string — not just the character — on which to split the string. So, for example, you could parse a hasty breakfast order by splitting on the word 'and':
>>> 'eggsandbaconandspam'.split('and')['eggs', 'bacon', 'spam']
Read now
Unlock full access