- Python语言从入门到精通
- 陈强编著
- 267字
- 2025-02-28 22:48:22
4.3 比较运算符和比较表达式

↑扫码看视频
比较运算符也被称为关系运算符,功能是表示两个变量之间的关系,例如经常使用关系运算符来比较两个数值的大小。比较表达式就是用比较运算符将两个表达式连接起来的式子,被连接的表达式可以是算数表达式、关系表达式、逻辑表达式和赋值表达式等。
Python语言共有6个比较运算符,下面假设变量a的值为10,变量b的值为20,表4-2列出了使用6个比较运算符处理变量a和变量b的结果。
表4-2 使用比较运算符的处理结果


实例文件bijiao.py的具体实现代码如下所示。

在上述代码中用到了“if else”语句,这将在本书第5章中进行讲解,本实例执行后会输出如下结果。
