它太热了我可能会被推迟.
>>> "/1/2/3/".split("/")
['', '1', '2', '3','']
Run Code Online (Sandbox Code Playgroud)
什么是开头和结尾的空元素?
编辑:谢谢大家,我把它归结为热诱导的大脑失败.从http://docs.python.org/library/stdtypes.html开始,文档并不是最清晰的
"Return a list of the words in the string, using sep as the delimiter string"
Run Code Online (Sandbox Code Playgroud)
在第一个之前,或在最后一个"/"之后是否有一个单词?
cee*_*yoz 18
与之比较:
"1/2/3".split("/")
Run Code Online (Sandbox Code Playgroud)
空元素仍然是元素.
您可以使用strip('/')从字符串的开头/结尾修剪分隔符.