Interview Prep/Python for DevOps/Language essentials & functions

What values are "falsy" in Python, and why does it matter in scripts?

BeginnerConceptLanguage essentials & functions
Answer

Falsy: None, False, 0, 0.0, "", [], {}, set(), (), and any object whose __bool__ returns False or __len__ returns 0. Everything else is truthy.

The trap is if not value: when 0 or "" is a legitimate value. For example, if not replicas: treats replicas=0 (a valid scale-down) as "not provided". Use if replicas is None: when you mean "missing".

All Python for DevOps questions Roadmap: Python for automation

More on Language essentials & functions