我是靠谱客的博主 炙热丝袜,这篇文章主要介绍python中,用input()输入一个整数,现在分享给大家,希望可以做个参考。

  我想用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中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部