Check if two numbers are equal

EasyIf-Else Programs · 43 of 64

Write a Python program to check whether two numbers are equal.

Advertisement
Input
(26, 88), (5, 5.0)
Output
26 88 -> the numbers are not equal
5 5.0 -> the numbers are equal

Approach

  1. Use ==.

Solution

Python
for a, b in [(26, 88), (5, 5.0)]:    if a == b:        print(a, b, "-> the numbers are equal")    else:        print(a, b, "-> the numbers are not equal")
Output
26 88 -> the numbers are not equal
5 5.0 -> the numbers are equal

Line by line

Line 2

5 == 5.0 is True because the values are equal even though the types differ.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs