Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我的代码
def(x): for i in range (0,x**2+1): ...
但是我发现它很慢!谁能告诉我原因,谢谢!
在 Python 2.x 中:range创建直到 stop 参数的所有数字的列表(在您的情况下看起来很大)。
range
您可以尝试使用xrange而不是创建迭代器而不是列表。
xrange