Python:“TypeError: list indices must be integers or slices, not str“问题解决方案
在做python基础课程最后的课程练习“名片管理系统”时候,在编写代码时候遇到错误:
TypeError: list indices must be integers or slices, not str
错误代码部分如下:
错误提示的意思是:
列表list的索引必须是整数或者切片,而不能是字符串类型。
在我写的代码中,利用for in循环将card_info中数据进行遍历,并将每一次取出的结果放于info中。
card_info定义为列表,其中存放着每一个名片信息组成的字典类型,我的本意是对字典类型中键"name"为name的值进行操作,却由于粗心对列表进行了操作。
将判断部分代码改成如下问题得到解决。
if info["name"] == name:
总结:在对列表进行取值操作时,索引必须是整数类型,或者直接进行切片取值。
Python:“TypeError: list indices must be integers or slices, not str“问题解决方案相关推荐
- “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: list indices must be integers or slices, not tuple
如果直接使用如下方法构造二维数据: test_list = [[0] * 5 for _ in range(5)] 取数时报错TypeError: list indices must be integ ...
- 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 【已解决】
Python 错误:TypeError String Indices Must be Integers [已解决] 如果你尝试使用字符串值,而不是整数值来访问字典或可迭代对象的值,那么你将收到以下错误 ...
- Python错误:TypeError: string indices must be integers
在项目遇到一个错误 : TypeError: string indices must be integers 由于是返回的接口数据,所以一时也分辨不出是哪里的错,然后我就还原了这样的场景: unico ...
- 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 ...
- TypeError: slice indices must be integers or None or have an __index__ method
在做人脸特征点检测时用python写的如下几行代码,一直运行有问题. 运行一直报 所划红线所在行出现" TypeError: slice indices must be integers o ...
最新文章
- UITableView 表视图编辑
- 【C010】Python - 基础教程学习(一)
- PL/SQL Developer中,存储过程无法调试的问题解决办法
- iqueryable怎么进行操作_C# 数据操作系列 - 16 SqlSugar 完结篇(最后的精华)
- javascript 模块模式
- 戴尔新鲜空气制冷的研究:在数据中心里面,让我们脱掉厚夹克换上一件夏威夷衬衫!...
- mysql004子查询.相关子查询.不相关子查询
- face-recognition库(人脸识别库)安装,使用
- 前端自适应----单位rem
- js 中断函数执行_js如何中断递归函数
- 云计算的2.0进化体现?区块链分化处理能力掀全球去中心化热潮
- php session失效
- Verilog三段式状态机描述
- python水果超市管理系统流程图_超市管理流程图-超市管理系统业务流程图
- GBase8s数据库MINUS 运算符
- [work] 一阶 二阶马尔可夫
- jzoj 3456 恭介的法则
- java ps old gen perm gen_java – JVM YoungGen 0%,Perm Gen 99%,OldGen Full
- mysql的时区设置
- 用h5的canvas实现动画的泡沫
热门文章
- 3. SQL 语句本身的优化(慢查询)
- 全国计算机应用考试试卷,全国信息化计算机应用技术水平教育考试试卷
- maven中引用JDK中的tools jar
- 迎接2019多校联合新生训练赛(2018/12/31)
- RabbitMQ实战:理解消息通信
- smpt authentification 配置
- 使用EntityFramework连接 Mysql
- 谷歌浏览器的一个新特点—关于获取iframe的parent对象
- ThingsBoard 提示Too many updates!
- Spring - 基于JPA的动态SQL执行器