Python Conditionals: Truthy and Falsy Values Explained

Python: Conditionals & Truthy/Falsy if name != "": print(f"Hello {name}") But in Python, you can do it the clean way 👇 if name: print(f"Hello {name}") Why? Because an empty string "" is falsy, Python treats it as False automatically. Common falsy values: False None 0 "" [] {} Quick test: print(bool(0)) # False print(bool("hi")) # True print(bool([])) # False print(bool([1, 2, 3])) # True Resource: https://lnkd.in/dEMihMwF #Python

To view or add a comment, sign in

Explore content categories