代码如图所示
Str = ' 这是一段长文本,我们需要将它转换为多行文本,从而实现不同场合下的应用!\
This is a long text, we need to convert it into multi line text, \
so as to realize the application in different occasions!'
Str = Str .strip()#去除前后空白字符串
def LongText_Convert(str, num):
new_str = ''
str_list = [str[i:i+num] for i in range(0,len(str),num)]
for i in range(0,len(str_list)):
new_str = new_str + str_list[i] + '\n'
return new_str
print(LongText_Convert(Str ,48))
实现效果
这个功能我将会用在文字转图片中,一起来玩吧~