如果定义一个以空格为结尾的字符串s,如果使用s[:-1],为何字符串最后的空格没有了,请问这是为何啊?
s[:-1] will only slice to the penultimate element
s[:-1]
[start:stop] 中會切出 start 到 stop-1.
[start:stop]
start
stop-1
All intervals in python are closed on the left and open on the right [m,n)
-1 is the last element, If you don’t want to remove the leading and trailing spaces, should you use strip()
A subsequence ofs[:-1]
will only slice to the penultimate element[start:stop]
中會切出start
到stop-1
.All intervals in python are closed on the left and open on the right [m,n)
-1 is the last element,
?If you don’t want to remove the leading and trailing spaces, should you use strip()