python基础之基本运算符
发布日期:2021-12-21 08:34 | 文章来源:站长之家
Python基本运算符
算数运算符
# + - * / % ** // 算数运算符 # 定义如下运算符 a=7 b=3 print(a+b) print(a-b) print(a*b) print(a/b) print(a%b) print(a//b) # 地板除,相除取整,也可进行复合运算
比较运算符
# == != < > >= <= 比较运算符 a,b=10,5 print(a==b) print(a!=b) print(a<=b) print(a>=b) print(a<b) print(a>b)
逻辑运算符
# and or not 逻辑运算符 # and 条件严格,都为真为真 # or 都为假为假 # not 非 真假切换,只需在前面加上not就可,对于需要取反操作的 a,b,c,d=23,16,26,56 print(a+b>c and c<d) print(a>b or c<d) print('--------not-------') print(a>b) print(not a>b)
# 优先级 # () -> not -> and -> or print (2>1 and 1<4 or 2<3 and 9>6 or 2<4)
赋值运算符
# 赋值运算 (算术运算的补充) # += -= /= %= **= *= a=10 b=1 c=4 d=5 a+=c print(a) b*=d print(d) d**=c ##数字为几即为几次方 print(d)
总结
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注本站的更多内容!
版权声明:本站文章来源标注为YINGSOO的内容版权均为本站所有,欢迎引用、转载,请保持原文完整并注明来源及原文链接。禁止复制或仿造本网站,禁止在非www.yingsoo.com所属的服务器上建立镜像,否则将依法追究法律责任。本站部分内容来源于网友推荐、互联网收集整理而来,仅供学习参考,不代表本站立场,如有内容涉嫌侵权,请联系alex-e#qq.com处理。
相关文章