0
Why??
a = 9**19 b = int(float(9**19)) Why a and b are not equal??
5 RĂ©ponses
+ 1
if it was
a == b
then I would say it should be equal
but
if it was
a is b
then I would say they are not âequalâ
this is because âisâ checks if it is exactly the same not only the same value. for example
if you have two twin dogs that look exactly the same then
twindog1 == twindog2
#true
they look exactly the same.
but
twindog1 is twindog2
#false
because even though they look the same they really arenât.
0
what kind of equal are you thinking about?
== or is ?
0
Brave Tea i am asking about ==
0
Iâm not sure enough. Iâm thinking that it has something to so with the range an integer and float can hold, and how they round. so in simpler terms: when you convert to a float it has to round it and change it so that it works as a float, and when you convert that float to an int it doesnt change it back, no it does a trick with rounding and stuff to make sure it fits in an int.
this is basically what ~ swim ~ said in simpler words.
also: donât worry too much about this. this is probably from a challenge and though those are often amusing and a great learning tool they are not always important for ârealâ coding. it is enough that you are aware of this problem and therefore if you ever run across a problem you can then try and figure it out.