PCEP Computer Programming and Python Fundamentals Practice Question
A developer is writing a Python script that stores the number of active user sessions in a variable. They want the variable to hold the value 42 as an integer. Which of the following statements correctly assigns the integer 42 to a variable named session_count?
⚠ Common exam trap
A common mix-up: candidates confuse string literals with numeric literals because they look similar when printed, and forgetting that Python does not use C-style type declarations.
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
✓
session_count = 42
The correct assignment uses the equals sign to bind the integer literal to the variable name. Python does not require type declarations, and the absence of quotes ensures the value is an int. The other options either create a string, use invalid syntax, or misuse an operator not intended for simple assignment.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
session_count = 42
Why this is correct
This assignment uses the equals sign to bind the integer literal 42 to the name session_count. In Python, variables are created on assignment; no type declaration is needed. The value is stored as an int because 42 has no decimal point or quotes, making this the correct way to store the integer.
- ✗
session_count := 42
Why it's wrong here
The walrus operator := is used for assignment expressions inside larger expressions, not as a standalone assignment statement. Using it alone like this would be a syntax error. To assign a value to a variable in a simple statement, the equals sign is required, not the walrus operator.
- ✗
session_count = '42'
Why it's wrong here
This assigns the string '42' rather than an integer. Although it looks like a number, the quotes make it a str type. If the script later performs arithmetic, such as adding 1 to session_count, Python would raise a TypeError because you cannot add an integer to a string directly. The scenario requires an integer.
- ✗
int session_count = 42
Why it's wrong here
This syntax mixes a type declaration with assignment, which is invalid in Python. Python is dynamically typed and does not use C-style declarations like 'int x = 42'. Attempting this would cause a SyntaxError. The correct approach is simply to assign the value without a type keyword.
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.