zoukankan      html  css  js  c++  java
  • Python 字符串

    Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。

    s1 = "-"
    s2 = ""
    seq = ("r", "u", "n", "o", "o", "b") # 字符串序列
    print (s1.join( seq ))
    print (s2.join( seq ))

    以上实例输出结果如下:

    r-u-n-o-o-b
    runoob
    Python split()通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则仅分隔 num+1 个子字符串
    str = "this is string example....wow!!!"
    print (str.split( )) # 以空格为分隔符
    print (str.split('i',1)) # 以 i 为分隔符
    print (str.split('w')) # 以 w 为分隔符
    ['this', 'is', 'string', 'example....wow!!!']
    ['th', 's is string example....wow!!!']
    ['this is string example....', 'o', '!!!']
     
  • 相关阅读:
    javaweb
    反射 day1
    JDBC-day1
    总结
    day5
    day4
    day3
    18.10.17 考试总结
    洛谷P2172 [bzoj] 2150 部落战争
    18.10.15 考试总结
  • 原文地址:https://www.cnblogs.com/xiaoxuesheng993/p/10794633.html
Copyright © 2011-2022 走看看