时间:2021-07-01 10:21:17 帮助过:16人阅读
split 是非常重要的字符串方法,它是join的逆方法,用来将字符串分割成序列
- >>> '1+2+3+4+5'.split('+')
- ['1', '2', '3', '4', '5']
- >>> 'usr/bin/env'.split('/')
- ['usr', 'bin', 'env']
- >>> 'usr/bin/env'.split('/')
- ['usr', 'bin', 'env']
- >>> '/usr/bin/env'.split('/')
- ['', 'usr', 'bin', 'env']
- >>> 'using the default'.split()
- ['using', 'the', 'default']
如果不提供任何分隔符,程序会把所有空格作为分隔符
希望本文所述对大家的Python程序设计有所帮助。