difficulty in understanding rsplit(None,1)[1]

Martin P. Hellwig martin.hellwig at dcuktec.org
Tue Sep 22 10:52:55 CEST 2009

hrishy wrote:
> Hi
> What does rsplit(None,1)[1] accomplish.
> Can somebody please decompose that to me.
> regards

 >>> test = 'This is a test'
 >>> help(test.rsplit)
Help on built-in function rsplit:

     S.rsplit([sep [,maxsplit]]) -> list of strings

     Return a list of the words in the string S, using sep as the
     delimiter string, starting at the end of the string and working
     to the front.  If maxsplit is given, at most maxsplit splits are
     done. If sep is not specified or is None, any whitespace string
     is a separator.

 >>> step_two = test.rsplit(None, 1)
 >>> step_two
['This is a', 'test']
 >>> step_two[1]

'If consumed, best digested with added seasoning to own preference.'

More information about the Python-list mailing list