首页 > 新闻中心 > 技术百科

python字符串截取前几位,python字符串截取从第2位到最后 返回列表

网络2023-08-28 00:00:00编辑发布,已经有个小可爱看过这篇文章啦

如下:

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位到最后》来自互联网同行内容,若有侵权,请联系我们删除!

  • 互联网
  • img
  • src
  • python
  • aliyucs
  • hongkong
  • space
  • gz
  • public
  • jpg

热门新闻

来电咨询