python print 输出方法

number1 = int(input("请输入第一个数:"))
number2 = int(input("请输入第二个数:"))

# 方法一:字符串拼接,注意数字需要str()转化为字符串再拼接
print(str(number1) + " + " + str(number2) + " = " + str(number1 + number2))

# 方法二:f"{变量}"
print(f"{number1} + {number2} = {number1 + number2}")

# 方法三:"%d" %变量
print("%d + %d = %d" % (number1, number2, number1 + number2))

# 方法四:"{编号}".format(变量)
print("{0} + {1} = {2}".format(number1, number2, number1 + number2))
# or
print("{number1} + {number2} = {number3}".format(number1=number1, number2=number2, number3=number1 + number2))
# or
print("{} + {} = {}".format(number1, number2, number1 + number2))

# 方法五:逗号和sep  
print('2024', '1', '29', sep='-') 

python print 输出方法_第1张图片

你可能感兴趣的:(python,python,开发语言)