'''
算数运算符,+、-、*、/、 //整除、**幂运算、%取模,两数相除的余数, 乘法如果是字符串和数字相乘,则会对字符串进行复制操作
赋值运算 =
+=: a+=5相当于a=a+5 类似有-=、*=、**=、/=、//=、%=
'''
num = 10
num = (num + 10) * 5
c = '*' * 3
print('num=', num, ',c=' + c) # num= 100 ,c=***
num /= 5
print('num=', num) # num= 20.0
# 关系运算符 > ,< ,>= ,!= ,is ,is not
# 逻辑运算符 not,and,or,可连着使用
result = 1 < 2 < 3
print('result=', result) # result= True
result1 = 1 < 2 and 2 > 3
print('result1=', result1) # result1= False
# 条件运算符 if...else...
a = 10
b = 12
max = a if a > b else b
print('a is bigger') if a > b else print('b is bigger') # b is bigger
print('max=', max) # max= 12
''' 运算符的优先级 由高到低
1)幂运算 **
2)正负号 +、-
3)算术操作符 *、/除法,返回浮点型、//整除,保留整数、+、-、%取模,求两个数相除的余数
4)比较操作符 >,<,>=,<=,!=,==
5)逻辑运算符 not,and,or
'''
# 定义三个变量代表成绩,写出分数之差及平均分
java = 100
python = 90
c = 86
print('java-c:', java - c) # java-c: 14
print('the average of three:', (c + java + python) / 3) # the average of three: 92.0
# 实现一个数字加密器,加密规则是:加密结果 = (整数 * 10 + 5) / 2 + 3.14159,加密结果仍是整数
a = 10
b = int((a * 10 + 5) / 2 + 3.14159)
print(b)
python学习-运算符
最新推荐文章于 2024-11-04 10:51:20 发布