220 Objective Assessment Practice Questions
with Detailed Answer Explanations | Bold
Italic Answers & Italic Rationales | Python
Certification Study Guide & Exam Review
Domain 1: Python Fundamentals & Syntax (Questions 1–30)
1. Which of the following correctly describes the purpose of
indentation in Python?
A) To make the code look organized for the programmer
B) To define blocks of code and control flow structure
C) To increase the execution speed of the program
D) To indicate comments within the code
Answer: B) To define blocks of code and control flow structure
Explanation: Python uses indentation to define the scope of control flow
statements, functions, and classes. Unlike many languages that use
braces, Python relies on consistent indentation to determine which
statements belong to which block.
,2. A developer writes a Python script and receives a SyntaxError for a
variable named 2nd_value. Which statement correctly describes
Python identifier naming rules?
A) Identifiers can start with a digit as long as the rest contains only
letters
B) Identifiers must start with a letter or underscore and cannot begin
with a digit
C) Identifiers are case-insensitive so 2nd_value is the same as
Second_Value
D) Identifiers can contain any character if enclosed in backticks
Answer: B) Identifiers must start with a letter or underscore and
cannot begin with a digit
Explanation: Python identifiers must begin with a letter (a-z, A-Z) or
underscore and can be followed by letters, digits, or underscores.
Starting with a digit like 2nd_value causes a SyntaxError. Python
identifiers are case-sensitive and backticks are not used.
3. Which of the following best describes the LEGB rule in Python?
A) A rule for naming variables using lowercase letters
B) The order of scope resolution: Local, Enclosing, Global, Built-in
C) A method for formatting strings with f-strings
D) A guideline for writing comments in code
Answer: B) The order of scope resolution: Local, Enclosing, Global,
Built-in
Explanation: Python follows LEGB (Local, Enclosing, Global, Built-in)
resolution to determine the scope of a variable. A variable assigned
inside a function is local to that function unless explicitly declared
global.
4. Which Python built-in function is used to capture user input from
the console and store it as a string?
,A) print()
B) input()
C) len()
D) type()
Answer: B) input()
Explanation: The input() function reads user input from the console and
always returns it as a string. To use the input as a number, it must be
converted using int() or float().
5. A systems administrator writes a Python script that needs to
prompt the user for an integer value and store it for calculation.
Which approach correctly reads and stores the integer?
A) Using input('Enter a number:') which automatically returns an
integer type
B) Using str(input('Enter a number:')) and relying on implicit conversion
during arithmetic
C) Using int(input('Enter a number:')) to read and convert the input in
one step
D) Using float(input('Enter a number:')) and truncating the decimal with
modulo
Answer: C) Using int(input('Enter a number:')) to read and convert the
input in one step
Explanation: The input() function always returns a string in Python 3, so
int() must wrap it to convert to an integer. Using input() alone stores a
string, str() wraps an already-string value, and float() returns a float,
not an int.
6. Which of the following is the correct way to concatenate a string
with an integer in Python?
A) 'Error: ' + error_code
B) 'Error: ' + str(error_code)
, C) 'Error: ' + int(error_code)
D) 'Error: ' . error_code
Answer: B) 'Error: ' + str(error_code)
Explanation: Python does not allow implicit conversion between strings
and integers. Using str() explicitly converts the integer to a string before
concatenation. Using int() on a string that contains a number will work,
but the result will be a number, not a string.
7. Which of the following best describes the primary use of
whitespace in Python?
A) To make the code more readable for humans only
B) To define the structure and hierarchy of the code
C) To separate statements on the same line
D) To indicate the end of a program
Answer: B) To define the structure and hierarchy of the code
Explanation: In Python, whitespace (specifically indentation) is
syntactically significant. It defines the structure and hierarchy of the
code, determining which statements belong to which blocks.
8. Which of the following is an example of a valid Python comment?
A) // This is a comment
B) /* This is a comment */
C) # This is a comment
D) -- This is a comment
Answer: C) # This is a comment
Explanation: Python uses the hash symbol (#) to denote comments.
Everything after the # on that line is ignored by the interpreter.
Comments are used for documentation and temporarily disabling code.
9. What is the purpose of the format() method in Python?
A) It enhances output formatting by embedding variables in strings