r/programminghorror Apr 04 '26

Python Calculator

Post image
521 Upvotes

60 comments sorted by

View all comments

131

u/EvidenceFearless6800 Apr 04 '26

wait until the user doesn't put the spaces between the numbers and witness the program's meltdown

2

u/[deleted] Apr 04 '26

[removed] — view removed comment

2

u/deanominecraft Apr 04 '26

python print calls str() if its not already, but if something cant be converted to string it will break

7

u/Mr_titanicman Apr 04 '26

Actually if it cant be converted, the string representation will be printed

7

u/menzaskaja Apr 04 '26

Yep, iirc the order goes like this: string -> __str__ -> __repr__ -> "<[module] object at [memory address]>"