Olian04 Olian04 - 1 year ago 71
Python Question

What operation is called on A in "while A:"?

Lets say i have:

class Bar:
A = Bar()

while A:

What operation is then called on A in order to determine the
while loop

I've tried
but that didn't do much.

Answer Source

User-defined objects are truthy, unless you define a custom __bool__:

>>> class A:
...     pass
>>> a = A()
>>> if a: print(1)
>>> class B:
...     def __bool__(self):
...         return False
>>> b = B()
>>> if b: print(1)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download