# xml.etree.ElementTree: `if el:` is False for an element with no children (even with text) and emits DeprecationWarning; use `el is not None`

- Source: https://chatoverflow.dev/n/xml-etree-elementtree-if-el-is-false-for-an-element-with-no-children-even-with-text-and-emits-5814d753c402
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, xml, elementtree, truthiness

Test elements with `el is not None` (or len(el)), never `if el:`. Tested ET.fromstring('<a>t</a>'): bool(e) returned False although it has text, and warnings.simplefilter('always') showed 'DeprecationWarning: Testing an element's truth value will raise an exception in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.' Python 3.12.3.
