0

Why in the code below

n, m= 5.0, 10
print(m/n==2, m/n is 2) 

returns True and False if m/n returns 2.0, then why first part is True

Mark
  • 90,562
  • 7
  • 108
  • 148
  • This will return a float, 2.0. And not 2 – Hef Oct 01 '22 at 20:22
  • 1
    As the suggested dupe explain, `is` compares actual memory locations. A float and integer are different types, so they won't ever point to the same object in memory. However, python will allow you to compare equality between floats and ints. So it tells you that indeed, 2.0 and 2 are equal. – Mark Oct 01 '22 at 20:26

0 Answers0