How do you compare 2 numbers in python?

PythonProgramming


Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

Mohammad Nauman

More Detail

Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

MANAS DASGUPTA

More Detail

Practical Data Science using Python

22 Lectures 6 hours

MANAS DASGUPTA

More Detail

You can use relational operators in python to compare numbers[both float and int] in python. These operators compare the values on either side of them and decide the relation among them. Assume variable a holds 10 and variable b holds 20, then

Operator
Example
==
[a == b] is not true.
!=
[a != b] is true.
>
[a > b] is not true.

=
[a >= b] is not true.
= b] print[a 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.
= ], equal to [ == ], and not equal to [ != ].

How do you compare two set values in Python?

The set[] function and == operator.
list1 = [11, 12, 13, 14, 15].
list2 = [12, 13, 11, 15, 14].
a = set[list1].
b = set[list2].
if a == b:.
print["The list1 and list2 are equal"].
print["The list1 and list2 are not equal"].

Chủ Đề