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)

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

 

相关文章:

  • 2021-09-19
  • 2022-12-23
  • 2021-12-23
  • 2021-08-04
  • 2021-11-17
  • 2021-10-08
猜你喜欢
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2021-09-25
相关资源
相似解决方案