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 ...
随机推荐
- Vivado 常见报错
1.[Synth 8-2543] port connections cannot be mixed ordered and named 说明例化时最后一个信号添加了一个逗号. 2. 原因:报告说明有一 ...
- Tensorflow從源碼編譯
从源代码构建 从源代码构建 TensorFlow pip 软件包并将其安装在 Ubuntu Linux 和 macOS 上.尽管这些说明可能适用于其他系统,但仅针对 Ubuntu 和 macOS 进行 ...
- Linux sort uniq 命令。简单运用
-n #代表以数字方法排序,如果倒序加上-r -t ':' #-t指定分隔符-k ...
- 来回最短路POJ3268
这个题得主要考点在于给你的图是去了再回来得有向图,如何模块化解决呢就是转变图的方向,我们根据初始得放心求出每个点到x得最短路,然后转变所有路得方向再求出所有点到x得最短路,最后一相加就是最后的来回了~ ...
- 理解ValueStack的基本机制 OGNL表达式
ValueStack基础:OGNL(Object Graphic Navigatino Language) OGNL是Struts2中使用的一种表达式语言. 它可以用于,在JSP页面,使用标签方便的访 ...
- Delphi for iOS开发指南(6):在iOS应用程序中使用ComboBox组件来从列表中选择某一项
http://blog.csdn.net/delphiteacher/article/details/8924110 Delphi for iOS开发指南(6):在iOS应用程序中使用ComboBox ...
- ListView的另一种可读性更强的ViewHolder模式写法
常见的写法是这样的: @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHol ...
- oracle 11g Enterprise Manager配置失败
Enterprise Manager以下简称em,Database Configuration Assistant简称DBCA. 病症 监听程序未启动或数据库服务未注册到该监听程序.启动该监听程序并注 ...
- Nginx an upstream response is buffered to a temporary file
1.错误日志:warn:an upstream response is buffered to a temporary file 解决办法:增加fastcgi_buffers 8 4K; fa ...
- C#委托、事件剖析(上)
本节对委托.事件做以总结. 一.委托: 1.概念:先来说明变量和函数的概念,变量,以某个地址为起点的一段内存中所存储的值,函数,以某个地址为起点的一段内存中存储的机器语言指令.有了这2个概念以后,我们 ...