Boolean values: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Consolidation.)
(→‎{{header|Python}}: ++String examples)
Line 61: Line 61:
A user-created class that defines a <tt>.__nonzero__()</tt> method to return False, or whose <tt>.__len__()</tt> method returns 0 will be treated as <code>False</code>, otherwise the class/instance is treated as <code>True</code>.
A user-created class that defines a <tt>.__nonzero__()</tt> method to return False, or whose <tt>.__len__()</tt> method returns 0 will be treated as <code>False</code>, otherwise the class/instance is treated as <code>True</code>.


Some examples:
'''Some examples:'''
<lang python>>>> True
<lang python>>>> True
True
True
Line 97: Line 97:
>>> bool({})
>>> bool({})
False
False
>>> bool("")
False
>>> bool("False")
True
>>> </lang>
>>> </lang>