python3xiaobaike_2020/chapter2/2-13 python3小白课:比较运算符.md
2025-04-20 23:22:14 +08:00

23 lines
661 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# python3小白课比较运算符
比较运算符是用来做比较的,很好理解,我们来直接看看例子再讲解:
```python
# coding:utf-8
# 比较运算符运算表达式的比较结果会返回布尔型True或者False注意大小写满足返回真否则返回假
a = 10
b = 5
# 大于
print(a > 3)
# 大于等于
print(a >= 10)
# 小于
print(b < a)
# 小于等于
print(1 <= b)
# 判断表达式是否值相等,注意用的两个等号,一个等号是赋值,注意区分和记忆
print(a == 10)
# 不等于在python2中<>、!=都表示不等于python3中不允许所以大家统一写!=即可
print(a != 10)
```