0

Why??

a = 9**19 b = int(float(9**19)) Why a and b are not equal??

25th Jul 2019, 1:50 PM
Akash
Akash - avatar
4 odpowiedzi
+ 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.
25th Jul 2019, 2:21 PM
Brave Tea
Brave Tea - avatar
0
what kind of equal are you thinking about? == or is ?
25th Jul 2019, 2:05 PM
Brave Tea
Brave Tea - avatar
0
Brave Tea i am asking about ==
27th Jul 2019, 11:14 AM
Akash
Akash - avatar
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.
27th Jul 2019, 12:15 PM
Brave Tea
Brave Tea - avatar