码迷,mamicode.com
首页 > 其他好文 > 详细

字符串split

时间:2018-10-29 13:18:15      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:any   rds   span   mit   bsp   done   ring   nbsp   known   

    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

标签:any   rds   span   mit   bsp   done   ring   nbsp   known   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!