Loading

python字符串截取

python字符串截取

str = 'abcd'

str[0:-1],-1表示末尾开始的位置,但是[]操作符不取尾下标所对应的字符;

所以str[0:-1] ---->‘abc'

str[0:100]返回的也是字符串'abcd',多了不报错;

str[0:0] 返回空字符串;

 

posted @ 2018-03-05 18:16  stono  阅读(279)  评论(0)    收藏  举报