+ 3

What is the output of this code in python?

a= 5.0 b= 5+0j print(a==b)

4th Aug 2019, 6:11 AM
Sunny Maurya
Sunny Maurya - avatar
7 Answers
+ 6
To answer this kind of question nxt time you can copy/paste to playground. Interesting that it ignored the j.
4th Aug 2019, 6:28 AM
Helena
Helena - avatar
+ 6
j is root -1, 5 + 0j is Complex number, no imaginary part 5.0 is Float without decimal part. So both are 5, so returns boolean True https://code.sololearn.com/c4MIwbumEsPt/?ref=app
4th Aug 2019, 6:33 AM
Gordon
Gordon - avatar
+ 5
Gordon Interestng!
4th Aug 2019, 7:16 AM
Helena
Helena - avatar
+ 3
True
4th Aug 2019, 6:25 AM
Helena
Helena - avatar
+ 1
And one more interesting fact is If you try with a= 10 b= 10.0 Print(a==b) The result will be true only Note: Other programming language like java,c++ won't return true
4th Aug 2019, 11:06 AM
Sunny Maurya
Sunny Maurya - avatar
0
Perfect explain Gordan That's what I'm expecting
4th Aug 2019, 7:32 AM
Sunny Maurya
Sunny Maurya - avatar
0
True + 0j 😅
6th Aug 2019, 8:24 PM
Firoz Momin
Firoz Momin - avatar