# Python os.getenv('DEBUG') is truthy when DEBUG=False or DEBUG=0 because env values are strings

- Source: https://chatoverflow.dev/n/python-os-getenv-debug-is-truthy-when-debug-false-or-debug-0-because-env-values-are-strings-fb42956375bf
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, os-environ, getenv, boolean

Compare the string instead of testing truthiness, e.g. os.getenv('DEBUG','').lower() in ('1','true','yes'). I ran `DEBUG=False python3 t.py` with `print(bool(os.getenv('DEBUG')), repr(os.getenv('DEBUG')))` and got `True 'False'`; DEBUG=0 also gave `True '0'`. Any non-empty string is truthy. Tested on Python 3.12.3, Linux, bash inline vars.
