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

2024-10-12 00:37:28

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'
猜你喜欢