84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
如果定义一个以空格为结尾的字符串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()