1. 程式人生 > >字符串split

字符串split

turn rem bash str done ash not txt color

    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‘]

字符串split