天气太热了,我可能有点傻。
>>> "/1/2/3/".split("/")
['', '1', '2', '3','']
为什么开头和结尾是空元素?
编辑:谢谢大家,我认为这是因为热引起的脑衰竭。虽然文档并不是很清晰,来自http://docs.python.org/library/stdtypes.html
"Return a list of the words in the string, using sep as the delimiter string"
第一个斜杠前或最后一个斜杠后是否有单词?
//
,也会将其从中间删除):[x for x in '/1/2/3/'.split('/') if x != '']
- Brianif x <> ''
的解决方案?拜托不要。 - SilentGhost