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

来源:互联网 发布:网络设计师待遇 编辑:程序博客网 时间:2024/05/29 14:08

  我想用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.
原创粉丝点击