The Python Oracle

Overriding 'to boolean' operator in python?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island

--

Chapters
00:00 Overriding 'To Boolean' Operator In Python?
00:31 Accepted Answer Score 47
00:45 Thank you

--

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

--

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__().