Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDillon Shaw
6,400 PointsIsn't True 0 and False 1?
It's been a while since I've worked with any programming language but I know that C/C++ programs, don't they return 0 on success and 1 on failure? Is Python switching this around for some reason or is success and failure for a program different from "truthiness"?
3 Answers
Jennifer Nordell
Treehouse TeacherIf I remember correctly (and it's been ages) so don't hold me to this, but in old school ANSI C you could return a 0 to indicate a normal exit from main. That was true even when main had a return type of void. But when I had it at university we were always told not to return 0 or 1 and instead return EXIT_SUCCESS which upon a failed exit of the function would result in an error code that you could then look up later.
But generally speaking, nowadays, 0 is considered "falsey" and any non-zero number is considered "truthy". Someone correct me if I'm wrong here! Thanks
edited for additional note
This is not exclusive to Python. This also includes JavaScript, Java, and PHP (and probably others).
Eduardo Calvachi
6,049 PointsDillon Shaw This boils down to what computers actually understand, after a prog language has been compiled or interpreted all the way down it, eventually gets to binary instructions in bytes(groups of bits). A bit can have either a 0 or 1 value. 0 represents off and 1 represents on. Since True and False are boolean operators with only 2 possible values, it makes sense to match them to the value that is actually stored in the computer memory.
Dillon Shaw
6,400 PointsOh okay and perhaps this is also related to what the video mentioned about None also being an option for boolean. (EXIT_SUCCESS no error)