Truth Value Testing in Python
Truth Value Testing
We can use any way to check the truth value of an object . By using ‘If’ statement or ‘While’ statement the checking can be done.
By default, an object is considered true unless its class defines either a __bool__() method that returns False or a __len__ method that returns zero, when called with the object.
Truth Value Testing :
- The truth value 0 is equivalent to False and 1 is same as True.
- When a variable contains different values like 0, 0.0, Fraction(0, 1), Decimal(0), then it signifies the False Value.
- Truth value of an empty sequence is False.
This is class Prep
It is True
This is class Insta
It is False