当前位置:Gxlcms > Python > python中split方法用法分析

python中split方法用法分析

时间:2021-07-01 10:21:17 帮助过:16人阅读

本文实例讲述了python中split方法用法。分享给大家供大家参考。具体分析如下:

split 是非常重要的字符串方法,它是join的逆方法,用来将字符串分割成序列

  1. >>> '1+2+3+4+5'.split('+')
  2. ['1', '2', '3', '4', '5']
  3. >>> 'usr/bin/env'.split('/')
  4. ['usr', 'bin', 'env']
  5. >>> 'usr/bin/env'.split('/')
  6. ['usr', 'bin', 'env']
  7. >>> '/usr/bin/env'.split('/')
  8. ['', 'usr', 'bin', 'env']
  9. >>> 'using the default'.split()
  10. ['using', 'the', 'default']

如果不提供任何分隔符,程序会把所有空格作为分隔符

希望本文所述对大家的Python程序设计有所帮助。

人气教程排行