方法一:
list_a = [1, 2, 3]
str_b = 'aaa'
string = "There are two contents:%s, %s" % (list_a, str_b)
print(string)
# 输出:
# There are two contents:[1, 2, 3], aaa
方法二:
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:531509025
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
list_a = [1, 2, 3]
str_b = 'aaa'
string = "There are two contents:{}, {}".format(list_a, str_b) # {}默认为输出对应变量的全部内容
print(string)
# 输出:
# There are two contents:[1, 2, 3], aaa
# 若变量为列表等可以通过索引取值的数据,可以在花括号里面加入索引
string = "There are two contents:{[2]}, {}".format(list_a, str_b)
print(string)
# 输出:
# There are two contents:3, aaa
# 可以看出,此时list_a输出的是索引2位置的数据
方法三:
list_a = [1, 2, 3]
str_b = 'ccc'
string = f"There are two contents:{list_a}, {str_b}"
print(string)
# 输出:
# There are two contents:[1, 2, 3], ccc