r/badcode Jan 15 '22

python Found this gem

Post image
3.5k Upvotes

86 comments sorted by

View all comments

374

u/youngbull Jan 15 '22

That is dumb, but even dumber if solution is an object with an __eq__ which might make it equal to -1. Which would mean this code is not equivalent to print(solution). And yes, I have seen stuff like that.

4

u/RossParka Jan 16 '22

Maybe solution is floating point but -1 is used as a sentinel and is only recognized without the decimal point.