new string method in 2.5 (partition)
johnjsal at NOSPAMgmail.com
Tue Sep 19 21:17:21 CEST 2006
richard.charts at gmail.com wrote:
> I'm confused.
> What's the difference between this and string.split?
>>> s = 'hello, world'
['hello', ' world']
('hello', ',', ' world')
split returns a list of the substrings on either side of the specified
partition returns a tuple of the substring on the left of the argument,
the argument itself, and the substring on the right. rpartition reads
from right to left.
But you raise a good point. Notice this:
>>> s = 'hello, world, how are you'
['hello', ' world', ' how are you']
('hello', ',', ' world, how are you')
split will return all substrings. partition (and rpartition) only return
the substrings before and after the first occurrence of the argument.
More information about the Python-list