WGU D335 OBJECTIVE ASSESSMENT
FINAL EXAM QUESTIONS AND
CORRECT ANSWERS (VERIFIED
ANSWERS) PLUS RATIONALES 2026 Q&A
| INSTANT DOWNLOAD PDF
CORE DOMAINS
• Python Fundamentals (Syntax, Data Types, Variables)
• Control Structures (Conditionals, Loops)
• Data Structures and Collections (Lists, Tuples, Dictionaries, Sets)
• Functions and Scope
• File Input/Output Operations
• Object-Oriented Programming (Classes, Objects, Inheritance)
• Error and Exception Handling
• Modules and Standard Library Utilities
INTRODUCTION
This comprehensive assessment is designed to evaluate your mastery of
the core competencies required for the WGU D335 Objective Assessment.
The examination covers a wide range of foundational and applied Python
programming concepts, including syntax, control flow, data structures, and
object-oriented programming. The questions are structured to test both
theoretical knowledge and practical, real-world application skills,
emphasizing decision-making and problem-solving abilities relevant to a
professional software development environment. You will encounter a
variety of question types, including multiple-choice, scenario-based, and
critical thinking prompts, all designed to rigorously assess your readiness.
,SECTION ONE: QUESTIONS 1-100
Question 1
Which of the following statements accurately describes the purpose of
the if __name__ == "__main__": construct in a Python script?
A. It ensures the script can only be imported as a module, not executed
directly.
B. It executes code only when the script is run directly, not when it is
imported as a module.
C. It defines a special variable that stores the command-line arguments
passed to the script.
D. It prevents the script from being imported by other modules.
B
RATIONALE: The if __name__ == "__main__": conditional block is a
common Python idiom. It checks if the current script is being executed
as the main program. When the script is run directly,
the __name__ variable is set to "__main__", causing the indented code to
execute. When the script is imported as a module, __name__ is set to the
module's name, preventing the code block from running. This allows
code to be used both as a standalone program and as a reusable
module.
Question 2
Consider the following Python code snippet:
python
def modify_list(lst):
lst.append(4)
lst = [5, 6, 7]
return lst
,my_list = [1, 2, 3]
new_list = modify_list(my_list)
print(my_list, new_list)
What is the output of the code?
A. [1, 2, 3] [5, 6, 7]
B. [1, 2, 3, 4] [5, 6, 7]
C. [1, 2, 3, 4] [1, 2, 3, 4]
D. [1, 2, 3] [1, 2, 3, 4, 5, 6, 7]
B
RATIONALE: The function modify_list first appends 4 to the list object
referenced by lst. Because lists are mutable and passed by reference,
this modifies my_list in place. The line lst = [5, 6, 7] rebinds the local
variable lst to a new list object, which does not affect the original
list my_list. The function then returns this new list [5, 6, 7], which is
assigned to new_list. Therefore, my_list is [1, 2, 3, 4] and new_list is [5,
6, 7].
Question 3
Which of the following is the correct way to open a file named "data.txt"
for both reading and writing without truncating the file, ensuring the file
pointer is at the beginning of the file if it exists?
A. file = open("data.txt", "r+")
B. file = open("data.txt", "w+")
C. file = open("data.txt", "a+")
D. file = open("data.txt", "x+")
A
RATIONALE: The mode "r+" opens the file for both reading and
writing. The file pointer is placed at the beginning of the file, and the file
, must already exist. This mode does not truncate the file, preserving its
existing content. In contrast, "w+" truncates the file, "a+" places the file
pointer at the end for appending, and "x+" creates a new file and raises
an error if it exists.
Question 4
A developer needs to create a class that represents a geometric shape.
Which method must be implemented to allow an object of this class to
be used with the built-in len() function, assuming the shape has a
meaningful size?
A. __len__(self)
B. __size__(self)
C. __length__(self)
D. __getitem__(self, key)
A
RATIONALE: The built-in len() function in Python calls an
object's __len__() special method. Implementing __len__(self) in a class
allows instances of that class to be passed as an argument to len(). The
other options are not standard special methods for this
purpose; __getitem__ is used for indexing and iteration.
Question 5
What is the primary difference between a list and a tuple in Python?
A. Lists are immutable; tuples are mutable.
B. Lists are mutable; tuples are immutable.
C. Lists can contain only one data type; tuples can contain multiple data
types.
D. Lists are used for fixed-size data; tuples are for dynamic data.
B
RATIONALE: The fundamental distinction between a list and a tuple
is mutability. Lists are mutable, meaning their elements can be added,
FINAL EXAM QUESTIONS AND
CORRECT ANSWERS (VERIFIED
ANSWERS) PLUS RATIONALES 2026 Q&A
| INSTANT DOWNLOAD PDF
CORE DOMAINS
• Python Fundamentals (Syntax, Data Types, Variables)
• Control Structures (Conditionals, Loops)
• Data Structures and Collections (Lists, Tuples, Dictionaries, Sets)
• Functions and Scope
• File Input/Output Operations
• Object-Oriented Programming (Classes, Objects, Inheritance)
• Error and Exception Handling
• Modules and Standard Library Utilities
INTRODUCTION
This comprehensive assessment is designed to evaluate your mastery of
the core competencies required for the WGU D335 Objective Assessment.
The examination covers a wide range of foundational and applied Python
programming concepts, including syntax, control flow, data structures, and
object-oriented programming. The questions are structured to test both
theoretical knowledge and practical, real-world application skills,
emphasizing decision-making and problem-solving abilities relevant to a
professional software development environment. You will encounter a
variety of question types, including multiple-choice, scenario-based, and
critical thinking prompts, all designed to rigorously assess your readiness.
,SECTION ONE: QUESTIONS 1-100
Question 1
Which of the following statements accurately describes the purpose of
the if __name__ == "__main__": construct in a Python script?
A. It ensures the script can only be imported as a module, not executed
directly.
B. It executes code only when the script is run directly, not when it is
imported as a module.
C. It defines a special variable that stores the command-line arguments
passed to the script.
D. It prevents the script from being imported by other modules.
B
RATIONALE: The if __name__ == "__main__": conditional block is a
common Python idiom. It checks if the current script is being executed
as the main program. When the script is run directly,
the __name__ variable is set to "__main__", causing the indented code to
execute. When the script is imported as a module, __name__ is set to the
module's name, preventing the code block from running. This allows
code to be used both as a standalone program and as a reusable
module.
Question 2
Consider the following Python code snippet:
python
def modify_list(lst):
lst.append(4)
lst = [5, 6, 7]
return lst
,my_list = [1, 2, 3]
new_list = modify_list(my_list)
print(my_list, new_list)
What is the output of the code?
A. [1, 2, 3] [5, 6, 7]
B. [1, 2, 3, 4] [5, 6, 7]
C. [1, 2, 3, 4] [1, 2, 3, 4]
D. [1, 2, 3] [1, 2, 3, 4, 5, 6, 7]
B
RATIONALE: The function modify_list first appends 4 to the list object
referenced by lst. Because lists are mutable and passed by reference,
this modifies my_list in place. The line lst = [5, 6, 7] rebinds the local
variable lst to a new list object, which does not affect the original
list my_list. The function then returns this new list [5, 6, 7], which is
assigned to new_list. Therefore, my_list is [1, 2, 3, 4] and new_list is [5,
6, 7].
Question 3
Which of the following is the correct way to open a file named "data.txt"
for both reading and writing without truncating the file, ensuring the file
pointer is at the beginning of the file if it exists?
A. file = open("data.txt", "r+")
B. file = open("data.txt", "w+")
C. file = open("data.txt", "a+")
D. file = open("data.txt", "x+")
A
RATIONALE: The mode "r+" opens the file for both reading and
writing. The file pointer is placed at the beginning of the file, and the file
, must already exist. This mode does not truncate the file, preserving its
existing content. In contrast, "w+" truncates the file, "a+" places the file
pointer at the end for appending, and "x+" creates a new file and raises
an error if it exists.
Question 4
A developer needs to create a class that represents a geometric shape.
Which method must be implemented to allow an object of this class to
be used with the built-in len() function, assuming the shape has a
meaningful size?
A. __len__(self)
B. __size__(self)
C. __length__(self)
D. __getitem__(self, key)
A
RATIONALE: The built-in len() function in Python calls an
object's __len__() special method. Implementing __len__(self) in a class
allows instances of that class to be passed as an argument to len(). The
other options are not standard special methods for this
purpose; __getitem__ is used for indexing and iteration.
Question 5
What is the primary difference between a list and a tuple in Python?
A. Lists are immutable; tuples are mutable.
B. Lists are mutable; tuples are immutable.
C. Lists can contain only one data type; tuples can contain multiple data
types.
D. Lists are used for fixed-size data; tuples are for dynamic data.
B
RATIONALE: The fundamental distinction between a list and a tuple
is mutability. Lists are mutable, meaning their elements can be added,