QA
Beginner LevelPython

Which built-in Python objects evaluate to False in boolean contexts (Falsy values)?

❓ Interview Prompt: Explain truthy and falsy object evaluation in `if` conditions, `bool()`, and exact list of falsy values.

In Python, every object can be evaluated in a boolean context (e.g. 'if obj:'):

Built-in Falsy Objects (Evaluate to 'False'):

•
'None' and 'False'
•
Numeric zero: '0', '0.0', '0j'
•
Empty collections & sequences: '""', '[]', '()', '{}', 'set()', 'range(0)'

Truthy Objects:

All other objects evaluate to 'True'! Custom objects evaluate to 'True' unless they implement '__bool__()' or '__len__()' returning zero.

Code Implementation Example

python
def process_items(items):
    if not items: # Checks if list is empty or None!
        print('No items provided!')
        return
    print(f'Processing {len(items)} items')
💡Checking empty collections using Pythonic falsy boolean evaluation.
🎯 Interview Key Takeaway

Use 'if not collection:' to check if lists, dicts, or strings are empty.

#Truthy#Falsy#Booleans#Beginner
Back to all Python Questions→

More Python Interview Questions

Beginner LevelPython

What is the Python Global Interpreter Lock (GIL) and how does it affect multi-threading?

Beginner LevelPython

What is the difference between a List, Tuple, Set, and Dictionary in Python?

Beginner LevelPython

Why are mutable default arguments (like def func(items=[])) dangerous in Python and how do you fix them?