All Subjects

Comparison operators

Definition

Comparison operators are used to compare two values and return a Boolean result (True or False). They are fundamental in decision-making constructs such as if statements.

5 Must Know Facts For Your Next Test

  1. The six main comparison operators in Python are ==, !=, >, <, >=, and <=.
  2. Comparison operators can be used to compare both numbers and strings.
  3. The equals operator (==) checks if two values are the same, while the not equals operator (!=) checks if they are different.
  4. The greater than (>) and less than (<) operators compare numerical values for magnitude.
  5. Comparison operators can be combined with logical operators for more complex conditions.

Review Questions

  • What is the difference between the == and != comparison operators?
  • Can comparison operators be used with string data types in Python?
  • How would you combine comparison operators with logical operators to create more complex conditions?

"Comparison operators" appears in:

Related terms

Boolean: A data type that has only two possible values: True or False.

Logical Operators: Operators such as and, or, and not that combine multiple Boolean expressions.

If Statement: A control flow statement that executes a block of code based on a condition being True.



© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.

© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.