太热了,我可能是智障了。
>>> "/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"
在第一个“/”之前或最后一个“/”之后有一个词吗?
最佳答案
比较:
"1/2/3".split("/")
空元素仍然是元素。
您可以使用 strip('/')
去除字符串开头/结尾的分隔符。
关于python - "/1/2/3/".split( "/"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3142428/