如何使用格式在输出中打印“ a”和“ b”的值而不是变量?
a = 1
b = 2
c = a+b
OUTPUT = Sum of 1 and 2 = 3
答案 0 :(得分:0)
这样做是否可以解决您的问题,请运行以下命令:
O(NK)
输出:
a = 1
b = 2
c = a+b
print("The sum of", a,"and", b,"=",c)
答案 1 :(得分:0)
a = 1
b = 2
c = a+b
print("Sum of",a,"and",b,"=",c)
答案 2 :(得分:0)
如果您使用Python> 3.6,则可以改用f字符串。它们更具可读性:
a = 1
b = 2
c = a+b
print(f"The sum of {a} and {b} = {c}")
输出为:
The sum of 1 and 2 = 3