是否有一种显而易见的方法可以解决这个问题?我只是想制作缩略图.
我想在python中检查int数据类型的大小:
import sys
sys.getsizeof(int)
Run Code Online (Sandbox Code Playgroud)
它出来是"436",这对我来说没有意义.无论如何,我想知道在我的机器上将占用多少字节(2,4,...?)int.
是否有可能在for循环中获得无限循环?
我的猜测是Python中可能存在无限循环.我想知道这个以供将来参考.
我正在做一些实验,并且正在尝试这样做:
import math
for i in range(math.inf):
print(i)
Run Code Online (Sandbox Code Playgroud)
我希望它与此完全相同:
c = 0
while True:
print(c)
c += 1
Run Code Online (Sandbox Code Playgroud)
但它更像这样
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer
Run Code Online (Sandbox Code Playgroud)
然后,我尝试将转换inf为浮点数:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer
Run Code Online (Sandbox Code Playgroud)
但这给了我这个错误,表明您不能将float infinity转换为整数。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: cannot convert float infinity …Run Code Online (Sandbox Code Playgroud) 我检查了Python持有的最大整数sys.maxsize,它返回了我9223372036854775807。
那为什么我仍然可以存储一个大于该范围的值?
存储一个整数需要多少个字节,Python是否根据整数的大小更改字节数?
我正在使用Python 3.6
python ×5
for-loop ×1
image ×1
infinite ×1
infinity ×1
loops ×1
math ×1
python-3.x ×1
thumbnails ×1