算术运算

基本类型 / 数字 / 整型

d1 = 8 + 2                # d1 is 10
d2 = 8 - 2                # d2 is 6
d3 = 8 * 2                # d3 is 16
# / is true division: a float
d4 = 8 / 2                # d4 is 4.0
d5 = 5 % 2                # d5 is 1
# Sign of the divisor, not -1
d6 = -5 % 2               # d6 is 1
d7 = 5 // 2               # d7 is 2
# Floors, not truncates
floored = -7 // 2         # floored is -4
d8 = 1
d8 += 1                   # d8 is 2
d8 -= 1                   # d8 is 1
# No ++: this is +(+d8)
plus_plus = ++d8           # plus_plus is 1, d8 is 1
d9, d8 = d8, d8 + 1       # d9 is 1, d8 is 2
d10, d8 = d8 + 1, d8 + 1  # d10 is 3, d8 is 3

# Quotient and remainder at once
quotient, remainder = divmod(7, 2)
# quotient is 3, remainder is 1

print(f"{d1 = }")
print(f"{d2 = }")
print(f"{d3 = }")
print(f"{d4 = }")
print(f"{d5 = }")
print(f"{d6 = }")
print(f"{d7 = }")
print(f"{floored = }")
print(f"{plus_plus = }")
print(f"{d8 = }")
print(f"{d9 = }")
print(f"{d10 = }")
print(f"{quotient = }")
print(f"{remainder = }")