脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python基础之基本运算符

python基础之基本运算符

2022-02-16 00:24qianqqqq_lu Python

这篇文章主要介绍了python基本运算符,实例分析了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) # 地板除,相除取整,也可进行复合运算

python基础之基本运算符

比较运算符

python基础之基本运算符

# == != < > >= <= 比较运算符
a,b=10,5
print(a==b)
print(a!=b)
print(a<=b)
print(a>=b)
print(a<b)
print(a>b)

python基础之基本运算符

逻辑运算符

python基础之基本运算符

# 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)

python基础之基本运算符

# 优先级
# () -> not -> and -> or
print (2>1 and 1<4 or 2<3 and 9>6 or 2<4)

python基础之基本运算符

赋值运算符

python基础之基本运算符

# 赋值运算 (算术运算的补充)
# += -= /= %= **= *=
a=10
b=1
c=4
d=5
a+=c
print(a)
b*=d
print(d)
d**=c  ##数字为几即为几次方
print(d)

python基础之基本运算符

 

总结

本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注服务器之家的更多内容!

原文链接:https://blog.csdn.net/weixin_44632711/article/details/120869227

延伸 · 阅读

精彩推荐