Files
2025PY/day03/02-算术运算符.py
2025-05-22 16:50:44 +08:00

46 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 算术(数学)运算符
# 1.+
# print(1 + 2) # 3
# print(1 + 2 + 3) # 6
# 注意字符串,拼接
# print('hello' + 'world') # helloworld
# 2.-
# 数字相减
# print(7 - 9) # -2
# print('zhang' - 'li') # 报错
# 3.*
# print(2 * 3) # 6
# 数字相乘
# print('zhang' * 'li') # 报错
# 4./
# print(8/3) # 2.6666666666666665
# 数字相除
# print(8/0) # 报错除数不能为0
# 5.// 取整除,商的整数部分,数字参与运算
# print(9 // 2) # 4
# print(9 // 3) # 3
# 6.% 取余数,求模
# print(9 % 2) # 1
# print(10 % 2) # 0
# 余数的意义:求奇数偶数,求是否可以整除......
# 7.** 求幂(指数)
# print(2 ** 3) # 2的3次方2是底数3是指数 结果:8
# print(12 ** 2) # 144
# 特殊情况
# 两个布尔值的运算True=1 False=0
print(True + True) # 1 + 1 = 2
print(True - True) # 1 - 1 = 0
print(True * True) # 1 * 1 = 1
print(True / True) # 1 / 1 = 1.0
print(True // True) # 1 // 1 = 1
print(True % True) # 1 % 1 = 0
print(True ** True) # 1 ** 1 = 1
print(True + False) # 1 + 0 = 1