python基础之基本运算符
更新时间:2021年10月22日 10:43:02 作者:qianqqqq_lu
这篇文章主要介绍了python基本运算符,实例分析了Python中返回一个返回值与多个返回值的方法,需要的朋友可以参考下
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)

总结
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注脚本之家的更多内容!
相关文章
在Sublime Editor中配置Python环境的详细教程
这篇文章主要介绍在sublime编辑器中安装python软件包,以 实现自动完成等功能,并在sublime编辑器本身中运行build,本文通过实例代码给大家介绍的非常详细,需要的朋友参考下吧2020-05-05
解决Scrapy安装错误:Microsoft Visual C++ 14.0 is required...
下面小编就为大家带来一篇解决Scrapy安装错误:Microsoft Visual C++ 14.0 is required...的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-10-10


最新评论