Bar*_*rtQ 1 python sys python-3.x
我需要生成一些零字符串,例如:
import sys
MB = 1024 * 1024
cache = ''
while sys.getsizeof(cache) <= 10 * MB:
cache = cache + "0"
Run Code Online (Sandbox Code Playgroud)
并将其保存到文件中,但我的印象是这种方法太慢,并且浪费大量系统资源。
尽可能快地做到这一点的最佳方法是什么?
您可以“乘”一个字符串:
cache = '0' * (1024**2)
Run Code Online (Sandbox Code Playgroud)
接收次数超过一百万次0。任何其他字符串或其他整数作为因子也可以。
| 归档时间: |
|
| 查看次数: |
2468 次 |
| 最近记录: |