Python - The fastest way to generate string of zeros
Question: I need to generate some string of zeros for example:

    
    
    import sys
    MB = 1024 * 1024
    cache = ''
    while sys.getsizeof(cache) <= 10 * MB:
        cache = cache + "0"
    

and save it to the file, but I have the impression that this method is too
slow, and waste a lot of system resources.

What is the best way to do it as fast as possible?


Answer: You can "multiply" a string:

    
    
    cache = '0' * (1024**2)
    

To receive more than a million times `0`. Any other string or other integer as
factor works as well.

