Skip to main content
Python Bug Hunt Easy +10 XP

Wrong Comparison

This always returns True for None checks.

PythonFind the bug
1def is_valid(value):
2 if value == None:
3 return False
4 return True
The bug is on line 2

Select the correct fix

Show answer and explanation

Answer: Use 'is None' instead of '== None'

In Python, the idiomatic way to check for None is 'is None', not '== None'. == can be overridden by classes.

Hint: Python has a special way to check None.

What this challenge tests

Bug Hunt in Python: none, identity, best-practices.

Related challenges