首页 > 其他 > 详细

字符串split

时间:2018-10-29 13:09:01      阅读:135      评论:0      收藏:0      [点我收藏+]
    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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!