Python基本澄清,不包括特殊字符或引号:基本澄清,Jupyter笔记

2024-04-26 20:19:48 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在输出中打印“a”和“b”的值而不是使用格式的变量

a = 1
b = 2
c = a+b
OUTPUT  = Sum of 1 and 2  = 3

Tags: andofoutput格式sum
3条回答
a = 1
b = 2
c = a+b
print("Sum of",a,"and",b,"=",c)

这是否解决了您的问题,请运行以下命令:

a = 1
b = 2
c = a+b

print("The sum of", a,"and", b,"=",c)

输出:

The sum of 1 and 2 = 3

如果使用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

相关问题 更多 >