运算符

算术运算符:+ - * / % //(整除) **(幂)
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
 
posted @   itsalexSun  阅读(62)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示