a = '123'
def concatenate_within_limit(b, new_string):
# 计算新字符串与a的长度之和
a = b
total_length = len(a) + len(new_string)
# 如果长度超过1024,从前面删除足够的字符
if total_length > 5:
diff = total_length - 5
a = a[diff:] + new_string # 删除前diff个字符,并拼接新字符串
else:
a += new_string # 长度未超过1024,直接拼接新字符串
# 返回处理后的a
return a
for i in range(4,10):
print(concatenate_within_limit(a, str(i)))