string indices must be integers:字符串索引必须是整数

一、使用字符串为索引

a = [1, 2, 3, 4]
print(a['0'])

‘0’为字符串,0才是整形。这种错误比较容易发现,实在不行可以使用type()函数检查索引类型

二、切片时用错符号。这里试图将’He is a hero’中的hero切片出来,有如下操作:

a = 'He is a hero'
print(a[8, 12])

运行报错TypeError: string indices must be integers

将‘,’改为‘:’即可,print(a[8:12])
符号写错了不容易检查。

string indices must be integers错误原因相关推荐

  1. python3 错误string indices must be integers 的解决方法

    这个错误意思是字符串的下标一定要是整数 出这种错误有多种可能,最形象直接的就是: a = '[abc]' print(a['0']) 有点pyhton基础的都知道下标怎么能是字符串'0',必须是整数0 ...

  2. Python错误:TypeError: string indices must be integers

    在项目遇到一个错误 : TypeError: string indices must be integers 由于是返回的接口数据,所以一时也分辨不出是哪里的错,然后我就还原了这样的场景: unico ...

  3. Python 错误:TypeError String Indices Must be Integers 【已解决】

    Python 错误:TypeError String Indices Must be Integers [已解决] 如果你尝试使用字符串值,而不是整数值来访问字典或可迭代对象的值,那么你将收到以下错误 ...

  4. 解决TypeError: string indices must be integers, not str

    遇到问题 ExtendValue = {"area": "1","info": "{\"year\": 201 ...

  5. TypeError: string indices must be integers

    1.错误描述 >>> print(st[-1,-6]); Traceback (most recent call last):File "<pyshell#13> ...

  6. python之解析 yaml配置文件时TypeError: string indices must be integers

    #定义一个SuperLogin登录函数,传递3个形参数 def SuperLogin(lANIP,username, password):driver = webdriver.Chrome()driv ...

  7. python string indices must be_Python解析json时提示“string indices must be integers”问题解决方法...

    本文实例讲述了Python解析json时提示"string indices must be integers"问题解决方法.分享给大家供大家参考,具体如下: import json ...

  8. python string indices must be_python报错string indices must be integers,怎么解决?

    展开全部 python报错string indices must be integers解决如下: 在.py文件中写的data={"a":"123"," ...

  9. ubuntu上训练yolov3: Caught ValueError in DataLoader worker process 0. string indices must be integers.

    最后train的代码: python3 train.py --model_def config/yolov3-custom.cfg --data_config config/custom.data 按 ...

最新文章

  1. 阅读笔记 CCL: Cross-modal Correlation Learning with Multi-grained Fusion by Hierarchical Network
  2. MySQL的库表详细操作
  3. [转载]项目风险管理七种武器-霸王枪
  4. nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException(Spring循环依赖问题)
  5. c语言 函数的参数传递示例_llround()函数以及C ++中的示例
  6. 飞鸽传书联系企业内部管理机制
  7. 中缅边境电信网络诈骗活动严重区域微信、支付宝等被封停
  8. Ubuntu 16.04 安裝chrome
  9. 讲解开源项目:让你成为灵魂画手的 JS 引擎:Zdog
  10. python+pytest接口自动化_python接口自动化11-pytest入门
  11. Delphi程序结构
  12. Windows 8 相关资源 MSDN原版
  13. 自动驾驶—高精度地图or人工智能or其他
  14. vmware station密钥
  15. 阿里云 mysql yum源_安装阿里云yum源
  16. 领域平均滤波 matlab,平均值滤波器 - MATLAB Simulink - MathWorks 中国
  17. 哪个软件测试交易系统好用,交易系统测试结果的可信度检验
  18. 计算机切换用户快捷键,Win10系统中快速切换用户有哪些快捷小技巧
  19. 2017已经接近尾声,然而我却什么都没干成
  20. 介绍一款非常好用的截图软件-《Snipaste》

热门文章

  1. 齐博x2新功能:如何对CMS等频道内容进行数据分表进行文本储值
  2. jQuery选中删除功能
  3. 电路自学1-运算放大器的电路模型+比例电路的分析+电路分析
  4. Windows Server 2012R2 IIS 详细配置(详解)
  5. 【深度之眼吴恩达机器学习第四期】笔记(七)
  6. 微服务中的熔断、限流、降级
  7. 影视APP搭建教程四个步骤
  8. 实验10-9 十进制转换二进制
  9. vue生命周期beforeCreate()前做了什么
  10. CSDN社群专属公开课课表