PCEP Computer Programming and Python Fundamentals Practice Question
Which TWO of the following code snippets will produce the output 'True'? (Assume all variables are defined appropriately.)
⚠ Common exam trap
The PCEP exam often tests the difference between `is` (identity) and `==` (equality), and the trap here is that candidates assume `is` compares values like `==` does, or they forget that integer interning is an implementation detail not guaranteed for all values.
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
✓
print(3.0 == int(3.0))
`int(3.0)` converts the float 3.0 to the integer 3, and the `==` operator compares values, not types. Since 3.0 and 3 represent the same numeric value, the comparison returns True. This demonstrates that `==` performs value equality, not identity.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
x=2.0; y=2.0; print(x is y)
Why it's wrong here
Float objects are not cached like small integers, so identity is False.
- ✗
print(1 < 2 < 1)
Why it's wrong here
Chained comparison: 1<2 is True, but 2<1 is False, so overall False.
- ✗
print('ab' == 'ba')
Why it's wrong here
Strings are different.
- ✓
print(3.0 == int(3.0))
Why this is correct
Value comparison coerces types, both equal 3.
- ✓
a=256; b=256; print(a is b)
Why this is correct
Integers from -5 to 256 are cached, so both reference same object.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 498-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 →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which of the following expressions will evaluate to True?
hard- ✓ A.3 == 3.0
- B.2 + 2 * 2 == 8
- C.10 / 3 == 3
- D.'a' > 'b'
Why A: Python's `==` operator performs value equality comparison, and the integer `3` and the float `3.0` represent the same numeric value. Python automatically converts the integer to a float for comparison, so `3 == 3.0` evaluates to `True`.
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.