- Learn Python in 7 Days
- Mohit Bhaskar N. Das
- 219字
- 2021-07-09 20:40:26
Comparison operators
Like any other language, Python also supports comparison operators. Comparison operators return True or False:

Some examples of comparison operators and their outcome are shown in the following screenshot:

Let's evaluate the following expression:
a < b < = c is equivalent to a<b and b<=c
Here, the and operator is used, b is evaluated only once, and c will not be evaluated if a < b is found False:

In the preceding example, 12<5 is evaluated first; if it is False, then the next expression will not be evaluated. If the operands are of different types, then they are converted to a common type. Otherwise, the == and != operators always consider objects of different types to be unequal.
Let's look at two different scenarios where we try to evaluate a float data type with an int data type, as shown:

Here, the operator evaluates to True in both the cases, as the interpreter converts one data type to another and then compares both the values.
Comparison between different data types:
- Numbers are compared arithmetically
- Strings are compared as per the alphabetical order, using the numeric equivalents
- Tuples and lists are compared according to the alphabetical order using the comparison of corresponding elements, which we will see in the coming chapters
- JavaScript從入門到精通(微視頻精編版)
- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- JavaScript 網頁編程從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- Dependency Injection in .NET Core 2.0
- 零基礎學Java(第4版)
- Banana Pi Cookbook
- 教孩子學編程:C++入門圖解
- 學習正則表達式
- 常用工具軟件立體化教程(微課版)
- Mastering Python Design Patterns
- Vue.js應用測試
- 嵌入式Linux C語言程序設計基礎教程
- 快樂編程:青少年思維訓練
- Mastering Bootstrap 4
- Mastering Drupal 8