字符串split

    def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
        """
        S.split(sep=None, maxsplit=-1) -> list of strings
        
        Return a list of the words in S, using sep as the
        delimiter string.  If maxsplit is given, at most maxsplit
        splits are done. If sep is not specified or is None, any
        whitespace string is a separator and empty strings are
        removed from the result.
        """
        return []
name='root:x:0:0::/root:/bin/bash'
print(name.split(':',2))

name='C:/a/b/c/d.txt'
print(name.split('/',1))

name="a|b|c"
print(name.rsplit('|',1))  #默认是从左边按分隔符开始分割,maxsplit,0等于不分割,1分割成二部分

['root', 'x', '0:0::/root:/bin/bash']
['C:', 'a/b/c/d.txt']
['a|b', 'c']

原文地址:https://www.cnblogs.com/wuxi9864/p/9870069.html