1MB所能存储汉字数量
1MB = 1兆字节 (megabyte) = 1024 × 1024 = 1,048,576 字节(byte)
utf-8编码,1mb空间能存储约35万个汉字,(一个汉字占3字节,存储英文占1字节)
with open('example8.txt', 'w', encoding='utf-8') as f:
counter = 0
while counter < 175000:
f.write('中国')
counter += 1
utf-16编码,1mb空间能存储约52万个汉字,(一个汉字占2字节,存储英文占2字节),存储汉字更节省空间
with open('example.txt', 'w', encoding='utf-16') as f:
f.write('中国' * 260000)

浙公网安备 33010602011771号