小编Bar*_*rtQ的帖子

生成零字符串的最快方法

我需要生成一些零字符串,例如:

import sys
MB = 1024 * 1024
cache = ''
while sys.getsizeof(cache) <= 10 * MB:
    cache = cache + "0"
Run Code Online (Sandbox Code Playgroud)

并将其保存到文件中,但我的印象是这种方法太慢,并且浪费大量系统资源。

尽可能快地做到这一点的最佳方法是什么?

python sys python-3.x

1
推荐指数
1
解决办法
2468
查看次数

标签 统计

python ×1

python-3.x ×1

sys ×1