不信网恋 发表于 2018-8-13 11:08:12

python内置数据结构之str-12064120

>>> s1  
"i'm \t a spuer student."
  
>>> s1.split()       # 默认为空白字符(包括\t)
  
["i'm", 'a', 'spuer', 'student.']
  

  
>>> s1.split(sep='\t')
  
["i'm ", ' a spuer student.']
  
>>> s1.split(sep='s')
  
["i'm \t a ", 'puer ', 'tudent.']
  

  
>>> s1.split(sep='s',maxsplit=1)
  
["i'm \t a ", 'puer student.']
  
>>> s1.split(sep='s',maxsplit=2)
  
["i'm \t a ", 'puer ', 'tudent.']
  
>>> s1.split(sep='s',maxsplit=3)
  
["i'm \t a ", 'puer ', 'tudent.']
  
>>> s1.split(sep='s',maxsplit=-2)       # 次数范围不合法,默认同-1
  
["i'm \t a ", 'puer ', 'tudent.']
页: [1]
查看完整版本: python内置数据结构之str-12064120