我的理解:
所以除非上面(1)(2)(3)是不正确的,否则为什么需要long()?当int()完成任务时? 对所有数字范围跳过long()会伤害我吗?
参考文档:
int类(x=0)
Return an integer object constructed from a number or string x, or return 0 if no arguments are given. If x is a number, it can be a plain integer, a long integer, or a floating point number. If x is floating point, the conversion truncates towards zero. If the argument is outside the integer range, the function returns a long object instead.
长类(x=0)
Return a long integer object constructed from a string or number x. If the argument is a string, it must contain a possibly signed number of arbitrary size, possibly embedded in whitespace. The base argument is interpreted in the same way as for int(), and may only be given when x is a string. Otherwise, the argument may be a plain or long integer or a floating point number, and a long integer with the same value is returned. Conversion of floating point numbers to integers truncates (towards zero). If no arguments are given, returns 0L.
代码试验
number = int(number_string) # cast it to integer
print number, "\t", type(number)
number = long(number_string) # cast it to long
print number, "\t", type(number)
int:整数;相当于Python 2.x中的C long,Python 3.x中的非限制长度
long:长度不受限制的长整数;仅存在于Python 2.x中
因此,在python 3x和about中,您可以使用int()而无需使用long()。
希望这能消除你的疑虑?
相关问题 更多 >
编程相关推荐