Content · Programming · Python

Python Conditions with None and Empty Values

None represents an absent value, while an empty string or empty list can be a legitimate present value. A truthiness check combines these cases, so use is None when the distinction matters. Learn with a clear example.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

This guide explains Conditions with None and Empty Values through a focused example and practical reasoning. No prior knowledge of this specific operation is required.

Understanding the Concept


None represents an absent value, while an empty string or empty list can be a legitimate present value. A truthiness check combines these cases, so use is None when the distinction matters.

When You Would Use This


An empty comment should be allowed even when the comment field is supplied.

Step-by-Step Example


comment_text = ""
if comment_text is None:
    print("Field was not supplied")
elif comment_text == "":
    print("User submitted an empty comment")
else:
    print("Comment:", comment_text)

How the Example Works


The second branch runs because the value is an empty string, not None. This distinction is useful in update forms and APIs.

Example Output


User submitted an empty comment

Try It Yourself


Test None, "", and "Hello" and explain all three outputs.

Common Beginner Mistakes


  • Using if not comment_text when empty and missing have different meanings.
  • Testing for None with == instead of the idiomatic identity check.
  • Treating zero as a missing number in every application.

Key Takeaways


  • None represents an absent value, while an empty string or empty list can be a legitimate present value.
  • The second branch runs because the value is an empty string, not None.
  • Avoid this mistake: Using if not comment_text when empty and missing have different meanings.
Share this resourceSend this page to someone who may find it useful.