运算符: 算数运算符:+ - * / % // ** 赋值运算符:= += -= *= /= **= //= %= 比较运算符:> < >= <= == != is 逻辑运算符:and or not
a = 1
b = 2
c = a + b
print(a, b, c)
print(c - a)
print(c * a)
print(c ** 2)
print(c / 2)
print(c // 2)
print(c % 2)
"""
练习:
键盘输入一个三位数的整数,打印个位数,十位数,百位数
"""
number = int(input('请输入一个三位数的整数:'))
print("个位数为", number % 10)
print("十位数为", number // 10 % 10)
print("百位数为", number // 100)
a = 10
b = 10
c = 10
d = 10
e = 10
f = 10
g = 10
a += 1
b -= 1
c *= 2
d /= 2
e **= 2
f //= 2
g %= 3
print('赋值运算符运算结果',a,b,c,d,e,f,g)
a = 10
b = 25
print(a > b)
print(a < b)
print(a == b)
print(a != b)
print(a is b)
字符串比较大小,比较ASC||码,从第一个字母开始往后比,一个字母一个字母比,当可以比出来的时候则不再继续往后比较
x = 'abc'
y = 'abd'
print(x == y)
print(x < y)
"""
输入考试分数,判断成绩是否在100到80之间
"""
score = float(input('输入分数:'))
print(80 <= score <= 100)
"""
输入两个商品的价格,比较两个商品的价格是否相同
"""
price1 = float(input('价格一:'))
price2 = float(input('价格二:'))
print(price1 == price2)
'''
A and B
False and False --> False
False and True --> False
True and False --> False
True and True --> True
'''
a = 1
b = 0
c = 2
print(b and a)
print(a > b and c < a)
print('-' * 30)
'''
A or B
False or False --> False
False or True --> True
True or False --> True
True or True --> True
'''
c = 0
d = 4
print(c or d)
print(a > b or c > a)
print(a == c or a < b)
print('-' * 30)
'''
not True --> False
not False --> True
'''
flag = True
print(not flag)
print(not a > c)
|