|
发表于 2020-10-27 22:36:10
|
显示全部楼层
>>> 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.
=======input()函数是获取并返回用户输入的字符串,返回值类型是字符串===========
>>> help(int)
Help on class int in module builtins:
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
==========int()函数说明文档已经写的很清楚了,字符串只接受‘+’‘—’号和纯数字==========
>>> int('-3')
-3
>>> int('+3')
3
>>> int('1.2')
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
int('1.2')
ValueError: invalid literal for int() with base 10: '1.2'
因此报错,错误在参数字符串型‘1.2’ |
|