您的位置:首页 > 编程语言 > Python开发

python中,用input()输入一个整数

2017-10-18 19:56 1226 查看
  我想用input()输入一个整数,结果报错:

  TypeError: ‘str’ object cannot be interpreted as an integer

  原来input()返回的值是str,比如输入5,其实得到的是 ‘5’

  其实只需要再用int()转换一下,就能得到我想要的整数了。

  这里是查看input的help:

>>>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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐