python的强制转换(当出现 not supported between instances of 'str' and 'int' 的错误时)
当我们编程时,有时会出现如下错误:TypeError: '>' not supported between instances of 'str' and 'int'
如下图:
这是因为input()返回的数据类型是str类型,不能直接和整数进行比较,必须先把str转换成整型,使用int()方法:age = int(input ("请输入你的年龄:"))
改正之后为:
这样程序就达到了预期的效果了
python的强制转换(当出现 not supported between instances of 'str' and 'int' 的错误时)的更多相关文章
- Python报错TypeError: '<' not supported between instances of 'str' and 'int'
n = input() if n>=100:print(int(n)/10) else:print(int(n)*10) 报错内容: Traceback (most recent call la ...
- python报错:not supported between instances of 'str' and 'int'
not supported between instances of 'str' and 'int' : 意思就是字符串不能和int类型的数值比较
- input()报错:TypeError: '>=' not supported between instances of 'str' and 'int'
今天学习python基础—分支与循环,接触到了if.在练习一个if语句的时候,出现了错误. 题目是: 根据分数划分成四个级别:优秀.良好.及格.不及格,分数是72: grade = 72if grad ...
- TypeError: '<' not supported between instances of 'str' and 'int'
<不支持str实例和int实例之间的对比 birth是str类型 2000是int类型 所以无法对比,报错 birth = input('birth: ') if birth < 2000 ...
- JAVA数据类型自动转换,与强制转换
一.数据类型自动转换 public class Test{ public static void main(String[] args){ int a = 1; double b = 1.5; dou ...
- Swift 2.2 多态和强制转换
写在前面: 写点东西,就是想告诉自己,有时间其实你也在前进着,快慢不说,至少没停下吧!该有的都会有的.不瞎BB了,说主题,3.0 的多态和继承. 总觉得继承好像也没什么太多的可说的了,在项目中用到的还 ...
- python 查看帮助和变量的强制转换
查看帮助 dir() 函数 查看对象都有哪些属性和方法 用法:把要查询的对象写入()括号中即可 print(dir([])) (查看列表的方法) 执行: C:\Python27\python.exe ...
- python 的 reshape强制转换格式的用途
shu=[[ 0.03046758], [ 0.05485586], [ 0.03282908], [ 0.02107211], [ 0.0391144 ], [ 0.07847244], [ 0.1 ...
- Python变量类型的强制转换
当我们需要对数据的类型转换时,只需要将数据类型作为函数名即可. 下面给出的函数可以执行数据类型之间的转换,函数返回一个新的对象,表示转换的值 函数格式 使用示例 描述 int(x [,base]) i ...
随机推荐
- derective示例
1.指令的定义 .directive('haproxySetting', [ function () { return { restrict: 'AEC', scope: { haproxy: '=' ...
- Linux 随记
通配符和文件名变量:* ? [] * 查询 $ ls doc1 doc2 document mydoc monday $ ls doc* doc1 doc2 document $ ls *day m ...
- 推荐:普通UI设计师与顶级UI设计师的区别是什么?(转)
我不是顶级设计师(我甚至不知道什么才叫顶级),即使见过的一些顶级(知名or优秀)设计师也因为交流不深入,无法评价.但是我勉强可以回答优秀的设计师,和普通的设计师(其实我觉得大部分的普通设计师只是认识他 ...
- (回文串 Manacher )Girls' research -- hdu -- 3294
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS Memory Limit:32 ...
- maven镜像
使用maven管理项目,下载依赖jar包的时候,经常会下载很慢,但是如果使用镜像的话,速度超级快~~只要在.m2/setting.xml文件中设置镜像就可以啦~ 本文来自https://yq.aliy ...
- Microsoft SQL Server 2012 管理 (2): Auditing
-- Demostratin 2A (Using SQL Server Audit) -- Step 1: Use the master database USE master; GO -- Step ...
- Mono For Android 之 配置环境
下载 Xamarin Mono For Android 4.6.07004 完整离线破解版 (包括除 Android SDK 外的所有文件) Android SDK. 资源源自 http://www. ...
- 在Windows 7上安装Team Foundation Server(TFS)的代理服务器(Agent)
自2009年微软发布Windows 7以来,经过8年的市场验证,Windows 7已经成为史上应用最为广泛的操作系统.但是面对技术变化的日新月异,2015年微软正式停止了对Windows 7的主流支持 ...
- Hibernate与Jpa的关系
JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. JPA的总体思想和现有Hibernate.T ...
- ie下警告console未定义
低版本IE6/7/8/9浏览器没有定义console对象,所以代码会中断执行.自己测试,ie11也没有(打开控制台的情况下可以用) 可以用如下代码完美解决. window.console = wind ...