Từ các tài liệu trên int
:
int(x=0) -> int or long
int(x, base=10) -> int or long
Nếu x là không phải là một số hoặc nếu cơ sở được đưa ra, sau đó x phải là một chuỗi hoặc Unicode đối tượng đại diện cho một chữ số nguyên trong cơ sở đã cho.
Vì vậy, '0.0'
là một số nguyên không hợp lệ theo nghĩa đen cho cơ sở 10
Bạn cần:
>>> int(float('0.0'))
0
giúp đỡ về int
:
>>> print int.__doc__
int(x=0) -> int or long
int(x, base=10) -> int or long
Convert a number or string to an integer, or return 0 if no arguments
are given. If x is floating point, the conversion truncates towards zero.
If x is outside the integer range, the function returns a long instead.
If x is not a number or if base is given, then x must be a string or
Unicode object 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('0b100', base=0)
4
Nguồn
2013-06-17 07:11:18