• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

nunca

但行好事 莫问前程
  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

python中的split方法

参考:http://www.runoob.com/python/att-string-split.html

Python split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串

语法:

str.split(str="", num=string.count(str))

其中str -- 分隔符,默认所有的空字符串,包括空格、换行(\n)、制表符(\t)等。

       num -- 分割次数

返回字符串列表。

实例代码

if __name__ == '__main__':
    s = "IndexError: string index out of range"
    print(s.split('i'))
    print(s.split('i',1))

输出为:
"""
['IndexError: str', 'ng ', 'ndex out of range']
['IndexError: str', 'ng index out of range']
"""

  

既然无论如何时间都会过去,为什么不选择做些有意义的事情呢

posted on 2018-03-27 06:47  乐晓东随笔  阅读(436)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3