算术运算符:+ - * / % //(整除) **(幂)
a = 6
b = 3
c = a + b
print(c - a)
print(c * a)
print(c / 2) #除法
print(c // 2) #整除
print(2 ** 3) # m ** n表示m的n次方
eg:键盘输入一个三位数,打印个位数、十位数、百位数
number = int(input('请输入一个三位数:'))
print('个位数是:',number % 10)
print('十位数是:',number // 10 % 10)
print('百位数是:',number // 100)
关系运算符: 结果: True False
> < >= <= == != is
输入考试分数,判断成绩是否在100到80之间?
score = float(input('请输入考试的分数:'))
print(80 <= score <=100)
price1 = float(input('请输入华为手机的价格:'))
price2 = float(input('请输入苹果手机的价格:'))
print( price1 == price2)
逻辑运算符: and or not
结果:
and: 与 并且
A and B :两侧有一个为假,则结果为假;两侧都为真,则结果为真。
or:或者
A or B :两侧只要有一侧为真,则结果为真
not:
not True---->False
not False--->True
'''
a = 1
b = 3
print(b and a) # and两边都是非0的数字,结果是最后的非0数字值
c = 0
print(c and a) #and两边只要有一个为0,则结果为0
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步