关于python切片的问题
巴扎黑
巴扎黑 2017-04-18 10:27:39
0
3
555

如果定义一个以空格为结尾的字符串s,如果使用s[:-1],为何字符串最后的空格没有了,请问这是为何啊?

巴扎黑
巴扎黑

reply all(3)
大家讲道理

s[:-1] will only slice to the penultimate element

A subsequence of

[start:stop] 中會切出 startstop-1.

大家讲道理

All intervals in python are closed on the left and open on the right [m,n)

Peter_Zhu

-1 is the last element,
If you don’t want to remove the leading and trailing spaces, should you use strip()

?
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template