The Python Oracle

Overriding 'to boolean' operator in python?

This video explains
Overriding 'to boolean' operator in python?

--

Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn

--

Track title: CC O Beethoven - Piano Sonata No 3 in C

--

Chapters
00:00 Question
00:49 Accepted answer (Score 44)
01:07 Thank you

--

Full question
https://stackoverflow.com/questions/7615...

Accepted answer links:
[__nonzero__()]: https://docs.python.org/2/reference/data...
[__bool__()]: https://docs.python.org/3/reference/data...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python

#avk47



ACCEPTED ANSWER

Score 47


In 2.x: override __nonzero__(). In 3.x, override __bool__().