我想用input()输入一个整数,结果报错:
TypeError: ‘str’ object cannot be interpreted as an integer
原来input()返回的值是str,比如输入5,其实得到的是 ‘5’
其实只需要再用int()转换一下,就能得到我想要的整数了。
这里是查看input的help:
复制代码
1
2
3
4
5
6
7
8
>>>help(input)
Help on built-in function input in module builtins:
input(prompt=None, /)
Read a string from standard input. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a
trailing newline before reading input.
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
On *nix systems, readline is used if available.
最后
以上就是炙热丝袜最近收集整理的关于python中,用input()输入一个整数的全部内容,更多相关python中内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复