法一:

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

法二:

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

相关文章:

  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2021-05-29
  • 2022-02-08
  • 2021-11-30
  • 2021-07-31
猜你喜欢
  • 2022-01-26
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-09-13
相关资源
相似解决方案