zoukankan      html  css  js  c++  java
  • split

    [split]

    1. str.split([sep[maxsplit]])

    Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified or -1, then there is no limit on the number of splits (all possible splits are made).

    If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings (for example, '1,,2'.split(',') returns ['1', '', '2']). The sep argument may consist of multiple characters (for example,'1<>2<>3'.split('<>') returns ['1', '2', '3']). Splitting an empty string with a specified separator returns [''].

    If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty string or a string consisting of just whitespace with a None separator returns [].

    For example, ' 1  2   3  '.split() returns ['1', '2', '3'], and '  1  2   3  '.split(None, 1) returns ['1', '2   3  '].

    2. 注意的要点:

      1) str.split() 与str.split(' ') 是不一样的, 不指定sep的会归并連续的空格

      2) 当使用显示sep时, 字符串头的sep和尾部的sep分别会产生一个空字符串项

    3. 实例代码:

      

     运行結果:

      

     4. awk 用-F指定sep与不指定sep的我与此类似

  • 相关阅读:
    Understanding performance, load and stress testing
    添加查看原型的插件
    Navicat Premium 15安装破解
    APP 测试 与 WEB 测试的本质区别
    app专项测试(稳定性测试、安全性测试)
    ubantu在登录界面一致循环的问题
    Ubuntu虚拟机安装
    装WIN7
    Linux线程模型浅析
    django中常用的数据查询方法
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3343184.html
Copyright © 2011-2022 走看看