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

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


hrishy wrote:
> Hi
>> What does rsplit(None,1)[1] accomplish.
>> Can somebody please decompose that to me.
>> regards
>Sure:
 >>> test = 'This is a test'
 >>> help(test.rsplit)
Help on built-in function rsplit:
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]
'test'
 >>>
-- 
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /