- The Python Apprentice
- Robert Smallshire Austin Bingham
- 135字
- 2021-07-02 22:16:54
Relational operators
Boolean values are commonly produced by Python’s relational operators which can be used for comparing objects. Two of the most widely used relational operators are Python's equality and inequality tests, which actually test for equivalence or inequivalence of values. That is, two objects are equivalent if one could use used in place of the other. We'll learn more about the notion of object equivalence later in the book. For now, we'll compare simple integers.
Let's start by assigning — or binding — a value to a variable g:
>>> g = 20
We test for equality with == as shown in the following command:
>>> g == 20
True
>>> g == 13
False
For inequality we use !=:
>>> g != 20
False
>>> g != 13
True
推薦閱讀
- 數據科學實戰手冊(R+Python)
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- Java面向對象思想與程序設計
- 少年輕松趣編程:用Scratch創作自己的小游戲
- Mastering QGIS
- Implementing Cisco Networking Solutions
- Silverlight魔幻銀燈
- 嚴密系統設計:方法、趨勢與挑戰
- Scala for Machine Learning(Second Edition)
- Instant Debian:Build a Web Server
- 編程可以很簡單
- 零基礎輕松學C++:青少年趣味編程(全彩版)
- Visual Basic語言程序設計基礎(第3版)
- 基于MATLAB的控制系統仿真及應用
- MySQL數據庫應用技術及實戰