python如何处理type(s) for +: 'int' and 'str'

2025-05-05 19:59:47

1、首先介绍下今天用到的python版本,现在在用的版本有两个:一个是python2.7.15,一个是python3.6.5。今天这里用到的是3的版本。

python如何处理type(s) for +: 'int' and 'str'

3、程序开始会正常运行,当输入数字1,系统就会提示错。提示为“TypeError: unsupported operand type(s) for +: 'int' and 'str'”,这个错误就是说输入的字符类型没有被系统判定为整数类型。

python如何处理type(s) for +: 'int' and 'str'

5、重新运行一下,看到这次就没有再次报错,程序正常运行并计算出了我们想要的结果。

python如何处理type(s) for +: 'int' and 'str'
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢