marat murad via Tutor <tutor@python.org> writes: > The author introduced a new way of coding the Boolean NOT operator > with the 'if' statement I have highlighted the relevant > area,apparently this if statement actually means if money != 0,which I > understood
Not quite. The statement actually means “if ‘money’ evaluates as true”. Any Python value can be interrogated with the question “Are you true or false?”, and that is what the ‘if’ statement does. This is different from asking ”Is this the True constant or the False constant?” because for most values the answer is ”Neither”. In Python the question “Is this value true, or false?” is usually implemented as ”Is this value something, or nothing?”. If the value is conceptually nothing, it evaluates as false when interrogated in a boolean context. See the Python documentation for a comprehensive list of false values <URL:https://docs.python.org/3/library/stdtypes.html#truth-value-testing>; any not-false value is true by default. If you learn the conceptual “if it's not something, it's false”, then you will have a fairly good intuition for how ‘if somevalue’ works. -- \ “None can love freedom heartily, but good men; the rest love | `\ not freedom, but license.” —John Milton | _o__) | Ben Finney _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor