python3-----往一个字符串中循环添加数据

a= "hello"

通过将a中的值不断的写入到b字符串中,得到b的的值类似如下:

hello,
hello,
hello,
hello

 

代码操作方式:

#!/usr/bin/env python
# coding = UTF-8
#Author:Lucky,time:2020/8/24
a = "hello"
b = ""
num = 3
for i in range(num):   #修改num值,可以不断向b中写入a的内容
    b+=a+",\n"
    if i==num-1:     #最后一行不需要加 逗号
        b+=a  

print("b的结果为如下:\n"+b)

 

posted @ 2020-08-26 17:52  Syw_文  阅读(2470)  评论(0编辑  收藏  举报