7

Python3中的比较运算符

 2 years ago
source link: https://blog.51cto.com/u_15320761/5634926
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python3中的比较运算符

精选 原创

一·比较运算符

python中的比较运算符,输出结果为布尔类型(bool)。

判断两边的值是否相等,相等输出True,不相等输出为False

判断两边的值是否为不相等,不相等输出True,相等输出为False

判断左边的值是否大于右边的值,是输出True,否输出False

判断左边的值是否小于右边的值,是输出True,否输出False

>=

判断左边的值是否大于或等于右边的值,是输出True,否输出False

<=

判断左边的值是否小于或等于右边的值,是输出True,否输出False

二·代码

print(1+1 == 2)
输出结果:True
print('a' == 'a')
输出结果:True
print(1+1 != 3)
输出结果:True
print(1+1 != 2)
输出结果:

3·>

print(2 > 1)
输出结果:True
print("2" > "1") # 也可以判断字符串里面数字的大小,
输出结果:True
print('啊' > '吧') # 如果比较的是文字,则是比较首字母次序,靠前的大
输出结果:True
print("章" > "张") # 如果拼音一样,那就比较笔画数量大小
输出结果:True

4·<

print(2 < 1)
输出结果:False
print(1 < 2)
输出结果:True

5·>=

print(2 >= 1)
输出结果:True

6·<=

print(2 <= 1)
输出结果:False
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK