Python-comparison-operators-example
提供:Dev Guides
Python比較演算子の例
これらの演算子は、それらの両側の値を比較し、それらの間の関係を決定します。 関係演算子とも呼ばれます。
変数aが10を保持し、変数bが20を保持すると仮定します-
Operator | Description | Example |
---|---|---|
== | If the values of two operands are equal, then the condition becomes true. | (a == b) is not true. |
!= | If values of two operands are not equal, then condition becomes true. | (a != b) is true. |
<> | If values of two operands are not equal, then condition becomes true. | (a <> b) is true. This is similar to != operator. |
> | If the value of left operand is greater than the value of right operand, then condition becomes true. | (a > b) is not true. |
< | If the value of left operand is less than the value of right operand, then condition becomes true. | (a < b) is true. |
>= | If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. | (a >= b) is not true. |
⇐ | If the value of left operand is less than or equal to the value of right operand, then condition becomes true. | (a ⇐ b) is true. |
例
変数aが10を保持し、変数bが20を保持すると仮定します-
上記のプログラムを実行すると、次の結果が生成されます-