字符串输出
a1 = float(input('a1 = '))
b2 = float(input('b2 = '))
# 用字符串输出
print(a1, '+', b2, '=', (a1 + b2))
print(a1, '-', b2, '=', (a1 - b2))
print(a1, '*', b2, '=', (a1 * b2))
print(a1, '/', b2, '=', (a1 / b2))
print(a1, '//', b2, '=', (a1 // b2))
print(a1, '%', b2, '=', (a1 % b2))
print(a1, '**', b2, '=', (a1 ** b2))
# 1.2 + 3.4 = 4.6
# 1.2 - 3.4 = -2.2
# 1.2 * 3.4 = 4.08
# 1.2 / 3.4 = 0.35294117647058826
# 1.2 // 3.4 = 0.0
# 1.2 % 3.4 = 1.2
# 1.2 ** 3.4 = 1.858729691979481
占位符格式化输出
a1 = float(input('a1 = '))
b2 = float(input('b2 = '))
# 占位符格式化输出
# float占位符%f
# int占位符%d
# %号后面可以定义保留小数点后几位
# %f或%d后面可以接固定字符串
print('%f + %f = %f' % (a1, b2, a1 + b2))
print('%f - %f = %.1f' % (a1, b2, a1 - b2))
print('%f * %f = %.2f' % (a1, b2, a1 * b2))
print('%f / %f = %.3f' % (a1, b2, a1 / b2))
print('%.1f // %.2f = %.3f' % (a1, b2, a1 // b2))
print('%.2f %% %.2f = %.2f' % (a1, b2, a1 % b2))
print('%f这里 ** %f可以加 = %f字符串' % (a1, b2, a1 ** b2))
# a1 = 1.2
# b2 = 3.4
# 1.200000 + 3.400000 = 4.600000
# 1.200000 - 3.400000 = -2.2
# 1.200000 * 3.400000 = 4.08
# 1.200000 / 3.400000 = 0.353
# 1.2 // 3.40 = 0.000
# 1.20 % 3.40 = 1.20
# 1.200000这里 ** 3.400000可以加 = 1.858730字符串
格式化输出
a1 = float(input('a1 = '))
b2 = float(input('b2 = '))
# 控制小数位数,在变量后增加:.2f
print(f'{a1}+{b2}={a1 + b2}')
print(f'{a1}-{b2}={a1 - b2}')
print(f'{a1}*{b2}={a1 * b2}')
print(f'{a1}/{b2}={a1 / b2}')
print(f'{a1}//{b2}={a1 // b2}')
print(f'{a1}这里%{b2}可以加={a1 % b2}字符串')
print(f'{a1}**{b2}={a1 ** b2:.2f}')