格式化输出的方法:%、.format()、f
a = '123'
a1 = '456'
a2 = '789'
%占位符
text = "a=%s"%a
text1 = "a=%s,a1=%s,a2=%s"%(a, a1, a2)
print(text)
print(text1)
.format()方法
text = "a={}".format(a)
text1 = "a={},a1={},a2={}".format(a, a1, a2) # 不指定下标,按顺序传
text2 = "a={0},a1={1},a2={2}".format(a, a1, a2) # 指定下标传值
print(text)
print(text1)
print(text2)
f方法(推荐):# 指定位置传指定值,代码简洁,不易出错
text = f'a={a}'
text1 = f'a={a},a1={a1},a2={a2}'
print(text)
讨论群:249728408