PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A function sometimes returns None. Which expression correctly checks if the return value is not None?
⚠ Common exam trap
Python Institute often tests the distinction between identity (`is`) and equality (`==`) operators, and the trap here is that candidates mistakenly use `!= None` (value comparison) instead of `is not None` (identity comparison), or confuse truthiness checks with `None` checks.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
if val is not None:
The `is not` operator is the proper way to check identity inequality in Python. Since `None` is a singleton, comparing with `is not` ensures you are checking whether the value is literally the `None` object, which is the recommended and most readable approach for `None` checks.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
if not val is None:
Why it's wrong here
Works but less readable.
- ✗
if val != None:
Why it's wrong here
Comparing with != invokes the object's __eq__ method, so a custom class overriding equality could return True against None and give a wrong result. It is tempting as the obvious-looking check, and it works for plain built-in types, but identity comparison with is not None is the reliable form.
- ✓
if val is not None:
Why this is correct
The identity operator is not None compares the object reference against the None singleton, which is the correct idiom for checking a missing return value. Equality operators can be overridden by custom __eq__ methods, so 'is not' is safer.
- ✗
if val:
Why it's wrong here
A bare truthiness test treats 0, empty strings, empty lists and False as falsy, so those legitimate return values would be misread as None. It is tempting because it is concise and works when the function only ever returns None or a non-empty object, but it does not test identity against None.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.