- 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
- JSP網(wǎng)絡編程(學習筆記)
- Intel Galileo Essentials
- Beginning Java Data Structures and Algorithms
- 零基礎玩轉區(qū)塊鏈
- 單片機C語言程序設計實訓100例:基于STC8051+Proteus仿真與實戰(zhàn)
- 架構不再難(全5冊)
- 深入理解Django:框架內幕與實現(xiàn)原理
- React Native Cookbook
- HTML5 Mobile Development Cookbook
- Practical DevOps
- 信息技術應用基礎
- Extending Puppet(Second Edition)
- Learning Apache Karaf
- Oracle實用教程
- Web編程基礎:HTML5、CSS3、JavaScript(第2版)