如下:
a[0]
a[1:3],中间是冒号,不是逗号;前面的下标小于后面的下标才有内容.
Python 2.7.5?
>>> a=\’Hello\’ print a[0]; File \”\”, line 1 a=\’Hello\’ print a[0]; ^SyntaxError: invalid syntax>>> a=\’Hello\’; print a[0];H>>> a=\’Hello\’; print a[2,4];Traceback (most recent call last): File \”\”, line 1, in TypeError: string indices must be integers, not tuple>>> a=\’Hello\’; print a[1,3];Traceback (most recent call last): File \”\”, line 1, in TypeError: string indices must be integers, not tuple>>> a=\’Hello\’; print a[1:3];el>>> a=\’Hello\’; print a[2:4];ll>>> a=\’Hello\’; print a[2:2];>>> a=\’Hello\’; print a[4:2];>>> a=\’Hello\’; print a[2:];llo>>>
end
21658812
《python字符串截取前几位,python字符串截取从第2位到最后》来自互联网同行内容,若有侵活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看权,请联系我们删除!
还没有评论,来说两句吧...