python列表报错TypeError: list indices must be integers or slices, not str
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相关推荐
- 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 ...
- “TypeError: list indices must be integers or slices, not str”有关报错解决方案
"TypeError: list indices must be integers or slices, not str"有关报错解决方案 参考文章: (1)"TypeE ...
- 成功解决TypeError: tuple indices must be integers or slices, not str
成功解决TypeError: tuple indices must be integers or slices, not str 目录 解决问题 解决思路 解决方法 解决问题 TypeError: t ...
- python报错 TypeError: string indices must be integers
所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({}) #检查不是字典 如果是字典,再看看有没有这样的属性: ...
- list indices must be integers or slices, not tuple
11年it研发经验,从一个会计转行为算法工程师,学过C#,c++,java,android,php,go,js,python,CNN神经网络,四千多篇博文,三千多篇原创,只为与你分享,共同成长,一起进 ...
- 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解决办法 ...
- Python错误:TypeError: string indices must be integers
在项目遇到一个错误 : TypeError: string indices must be integers 由于是返回的接口数据,所以一时也分辨不出是哪里的错,然后我就还原了这样的场景: unico ...
- Python 错误:TypeError String Indices Must be Integers 【已解决】
Python 错误:TypeError String Indices Must be Integers [已解决] 如果你尝试使用字符串值,而不是整数值来访问字典或可迭代对象的值,那么你将收到以下错误 ...
- python之解析 yaml配置文件时TypeError: string indices must be integers
#定义一个SuperLogin登录函数,传递3个形参数 def SuperLogin(lANIP,username, password):driver = webdriver.Chrome()driv ...
- 解决TypeError: string indices must be integers, not str
遇到问题 ExtendValue = {"area": "1","info": "{\"year\": 201 ...
最新文章
- 关于Facebook iOS UI 工具ComponentKit简介
- 基于Springboot实现就业管理系统
- 动态生成CheckBox(Winform程序)
- 剑指offer(一):二维数组中的查找
- 领域驱动设计之单元测试最佳实践(二)
- VS返回到上次编辑和进入到下次编辑的位置快捷键
- Linux下如何用GDB调试c++程序 [版本2]
- Linux(CentOS7)虚拟机安装详解
- Unity 游戏实例开发集合 之 JumpJump (简单跳一跳) 休闲小游戏快速实现
- 分析家数据格式、结构
- 迷你世界一直显示服务器未连接,迷你世界为什么显示没网 | 手游网游页游攻略大全...
- 1_01_GLib库入门与实践_GLib库简介
- [Web端接入经验分享] 腾讯云即时通信TIM、实时音视频TRTC
- 自适应,响应式以及图片的性能优化(响应式图片)
- ABAP select options 和 parameters在同一行
- webpack加载css样式 ----css相关loader
- 数学的回忆(二)——麦克斯韦方程
- MySQL - change 和 modify 的区别
- 【STM32】超声波传感器HC-SR04知识
- 【身份证识别】基于matlab GUI身份证号码识别【含Matlab源码 014期】