python在写代码的时候运行时发现列表那里报错

代码:

n=input("")
RESULT[n]='\"'+RESULT[n]+'\"'
print(RESULT[n])

报错TypeError: list indices must be integers or slices, not str
报错翻译过来意思是:TypeError:列表索引必须是整数或片,而不是str
这是在说索引目标不能是个字符,这就意味着 RESULT[n] 里的 n 是个字符串型,不是整形

当我的鼠标移到n那里时

果然啊,n是个字符串型,因为列表索引中必须是整数或片,这字符串指定是要报错的

变量在输入时就要考虑要用在的位置!!!
改一下就好了:

n=int(input(""))
RESULT[n]='\"'+RESULT[n]+'\"'
print(RESULT[n])

python列表报错TypeError: list indices must be integers or slices, not str相关推荐

  1. python二维数组读取数报错TypeError: list indices must be integers or slices, not tuple

    如果直接使用如下方法构造二维数据: test_list = [[0] * 5 for _ in range(5)] 取数时报错TypeError: list indices must be integ ...

  2. “TypeError: list indices must be integers or slices, not str”有关报错解决方案

    "TypeError: list indices must be integers or slices, not str"有关报错解决方案 参考文章: (1)"TypeE ...

  3. 成功解决TypeError: tuple indices must be integers or slices, not str

    成功解决TypeError: tuple indices must be integers or slices, not str 目录 解决问题 解决思路 解决方法 解决问题 TypeError: t ...

  4. python报错 TypeError: string indices must be integers

    所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({})             #检查不是字典 如果是字典,再看看有没有这样的属性: ...

  5. list indices must be integers or slices, not tuple

    11年it研发经验,从一个会计转行为算法工程师,学过C#,c++,java,android,php,go,js,python,CNN神经网络,四千多篇博文,三千多篇原创,只为与你分享,共同成长,一起进 ...

  6. Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法

    Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法 ...

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

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

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

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

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

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

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

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

最新文章

  1. 关于Facebook iOS UI 工具ComponentKit简介
  2. 基于Springboot实现就业管理系统
  3. 动态生成CheckBox(Winform程序)
  4. 剑指offer(一):二维数组中的查找
  5. 领域驱动设计之单元测试最佳实践(二)
  6. VS返回到上次编辑和进入到下次编辑的位置快捷键
  7. Linux下如何用GDB调试c++程序 [版本2]
  8. Linux(CentOS7)虚拟机安装详解
  9. Unity 游戏实例开发集合 之 JumpJump (简单跳一跳) 休闲小游戏快速实现
  10. 分析家数据格式、结构
  11. 迷你世界一直显示服务器未连接,迷你世界为什么显示没网 | 手游网游页游攻略大全...
  12. 1_01_GLib库入门与实践_GLib库简介
  13. [Web端接入经验分享] 腾讯云即时通信TIM、实时音视频TRTC
  14. 自适应,响应式以及图片的性能优化(响应式图片)
  15. ABAP select options 和 parameters在同一行
  16. webpack加载css样式 ----css相关loader
  17. 数学的回忆(二)——麦克斯韦方程
  18. MySQL - change 和 modify 的区别
  19. 【STM32】超声波传感器HC-SR04知识
  20. 【身份证识别】基于matlab GUI身份证号码识别【含Matlab源码 014期】

热门文章

  1. 前端工程师未来发展方向
  2. 微服务网关SIA-GateWay使用指南 ===
  3. 每日简报 4月22日简报新鲜事 每天一分钟 了解新鲜事
  4. 推荐一款免费开源的GIF动图软件(录制,编辑,压缩)
  5. LeetCode 一题多解 | 53. 最大子数组和:五种解法完全手册
  6. word快速切换多个文件窗口
  7. 分享美容护肤门店预约下单小程序开发制作功能介绍
  8. Oracle Analyze
  9. 工作缺点和不足及措施_工作总结中的不足与改进该怎么写?
  10. 思科的DUO解决方案到底是什么?