# Python Truth Value Testing Explained - A Python Programming Tutorial

**URL:** <https://forum.freecodecamp.org/t/python-truth-value-testing-explained-a-python-programming-tutorial/19166>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [July 11, 2016, 2:14am UTC](https://forum.freecodecamp.org/t/python-truth-value-testing-explained-a-python-programming-tutorial/19166 "2016-07-11T02:14:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [July 11, 2016, 2:14am UTC](https://forum.freecodecamp.org/t/python-truth-value-testing-explained-a-python-programming-tutorial/19166/1 "2016-07-11T02:14:26Z")

</div>

Any object can be tested for truth value, for use in an `if` or `while` condition or as operand of a Boolean operation like `and` , `or` , or `not` .

The following values are considered false:

- `None`
- `False`
- zero of any numeric type, for example, `0` , `0.0` , `0j` , `Decimal(0)` , `Fraction(0, 1)` .
- any empty sequence, for example, `''` , `()` , `[]` , `set()` , `range(0)` .
- any empty mapping, for example, `{}` .
- instances of user-defined classes, if the class defines a ` __bool__ ()` or ` __len__ ()` method, when that method returns `False` or `0` .

All other values are considered true – so objects of many types are always true.

Operations and built-in functions that have a Boolean result always return `0` or `False` for false and `1` or `True` for true, unless otherwise stated. (Important exception: the Boolean operations `or` and `and` always return one of their operands.)

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [August 7, 2017, 1:45am UTC](https://forum.freecodecamp.org/t/python-truth-value-testing-explained-a-python-programming-tutorial/19166/2 "2017-08-07T01:45:52Z")

</div>


