English documents:
class int (x=0) class int (x, base=10)
Return an integer object constructed from a number or string x, or return 0 if no arguments is 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 are a string, bytes, or ByteArray instance representing an integer li Teral in Radix base. Optionally, the literal can be preceded by + or – (with no space in between) and surrounded by whitespace. A base-n literal consists of the digits 0 to n-1 and with A to Z (or A to Z) has the values of 35. The default base is 10. The allowed values are 0 and 2-36. Base-2,-8, and-16 literals can be optionally prefixed with 0b/0b, 0o/0o, or 0x/0x, as with the integer literals in code. Base 0 means to interpret exactly as a code literal, so then the actual base is 2, 8, ten, or, and so that int (' 010 ', 0) Is isn't legal, while INT (' 010 ') are, as well as int (' 010 ', 8).
Description
1. When the parameter is not passed in, the result 0 is obtained.
>>> Int () 0
2. When passing in a value, call its __int__ () method, and the floating-point number will be rounded down.
>>> Int (3) 3>>> int (3.6) 3
3. When a string is passed in, the conversion is made by default in 10 binary.
>>> int (' 1 ') 36>>> int (' 3.6 ') Traceback (most recent call last): File "<pyshell#2>", line, In <module> int (' 3.6 ') valueerror:invalid literal for int. () with base 10: ' 3.6 '
4. The string is allowed to contain "+", "-" number, but plus minus and number can not have spaces, after the value, the symbol can appear before the space.
>>> int (' +36 ') 36>>> int (' -36 ') -36>>> int (' -36 ') -36>>> int ('-- Traceback (most recent): File "<pyshell#7>", line 1, in <module> int ('- ') valueerr Or:invalid literal for int. () with base 10: '-36
5. When the string is passed in, and the binary is specified, the string is converted to a 10-binary integer by the corresponding binary.
>>> int (' 0f ', 2) 1>>> int (' 2>>> ', 3) ' int ' (' "', ' 8 ') ' 7>>> int ' (' ', 16) 15