WGU D335 OA:
Introduction to Programming in Python Objective Assessment
Questions and Answers| Latest Update| Guaranteed Pass
1. Which of the following is used to write a single-line comment in Python?
A. // comment
B. /* comment */
C. # comment
D. <!-- comment -->
Answer: C
Rationale: Python uses the pound sign (#) to begin a single-line comment;
everything after it on that line is ignored by the interpreter.
2. Which function is used to display output to the console in Python?
A. print()
B. echo()
C. display()
D. console.log()
Answer: A
Rationale: The built-in print() function is used to output text or values to the
console in Python.
3. What symbol does Python use to indicate the end of a statement (in most cases)?
A. A semicolon (required)
B. A colon
C. A newline (no semicolon required)
D. A period
, Answer: C
Rationale: Unlike many languages, Python does not require a semicolon to end a
statement; a newline is normally sufficient, although semicolons can optionally
separate statements on the same line.
4. How does Python define blocks of code, such as the body of a loop or function?
A. Curly braces {}
B. Indentation
C. Parentheses ()
D. The keyword 'begin' and 'end'
Answer: B
Rationale: Python uses consistent indentation (whitespace) to define code blocks,
rather than curly braces or explicit begin/end keywords.
5. What is the correct file extension for a Python script?
.pt
.py
.pyt
.python
Answer: B
Rationale: Python script files conventionally use the .py extension.
6. Which of the following is a valid Python variable name?
A. 2ndvalue
B. my-value
C. _value2
D. class
Answer: C
Rationale: Variable names can start with an underscore or a letter, and can
include numbers after the first character. '2ndvalue' starts with a digit (invalid),
'my-value' contains a hyphen (invalid), and 'class' is a reserved keyword.
7. What will the following code print?
print('Hello,', 'World!')
A. Hello,World!
B. Hello, World!
C. 'Hello,' 'World!'
, D. An error
Answer: B
Rationale: When print() is given multiple arguments separated by commas, it joins
them with a single space by default, producing 'Hello, World!'.
8. Which keyword is used to import a module in Python?
A. include
B. import
C. using
D. require
Answer: B
Rationale: The 'import' keyword is used to bring the contents of a module into the
current namespace, for example: import math.
9. What does the input() function do in Python?
A. Reads a line of text input from the user and returns it as a string
B. Reads a number only
C. Writes text to a file
D. Executes a shell command
Answer: A
Rationale: The input() function pauses program execution, waits for the user to
type text and press Enter, and returns that text as a string.
10. What is the correct way to start a multi-line comment/docstring in Python?
A. Triple quotes: """ """
B. /* */
C. <!-- -->
D. ## ##
Answer: A
Rationale: Triple quotes (either """ or ''') are used to create multi-line strings,
which are commonly used as docstrings or block comments in Python.
11. Which of the following is considered a Python keyword and cannot be used as a
variable name?
A. value
B. total
C. False
, D. number
Answer: C
Rationale: 'False' (along with 'True', 'None', 'if', 'for', etc.) is a reserved Python
keyword and cannot be used as a variable identifier.
12. What is the output of: print(type(5))
A. <class 'str'>
B. <class 'int'>
C. <class 'float'>
D. <class 'number'>
Answer: B
Rationale: The literal 5 is a whole number with no decimal point, so Python
interprets it as an int, and type(5) returns <class 'int'>.
13. Which of the following correctly assigns the value 10 to a variable named x?
A. x = 10
B. x := 10
C. let x = 10
D. int x = 10
Answer: A
Rationale: Python uses a simple equals sign for assignment: x = 10. It does not
require type declarations or special assignment operators for basic assignment.
14. What does the Python interpreter do when it encounters indentation that does
not match the surrounding block?
A. Ignores it silently
B. Raises an IndentationError
C. Automatically corrects it
D. Converts it to a comment
Answer: B
Rationale: Python relies on consistent indentation to define code blocks;
mismatched or inconsistent indentation raises an IndentationError.
15. Which of the following is NOT a valid way to run a Python script named app.py
from the command line?
A. python app.py
B. python3 app.py
Introduction to Programming in Python Objective Assessment
Questions and Answers| Latest Update| Guaranteed Pass
1. Which of the following is used to write a single-line comment in Python?
A. // comment
B. /* comment */
C. # comment
D. <!-- comment -->
Answer: C
Rationale: Python uses the pound sign (#) to begin a single-line comment;
everything after it on that line is ignored by the interpreter.
2. Which function is used to display output to the console in Python?
A. print()
B. echo()
C. display()
D. console.log()
Answer: A
Rationale: The built-in print() function is used to output text or values to the
console in Python.
3. What symbol does Python use to indicate the end of a statement (in most cases)?
A. A semicolon (required)
B. A colon
C. A newline (no semicolon required)
D. A period
, Answer: C
Rationale: Unlike many languages, Python does not require a semicolon to end a
statement; a newline is normally sufficient, although semicolons can optionally
separate statements on the same line.
4. How does Python define blocks of code, such as the body of a loop or function?
A. Curly braces {}
B. Indentation
C. Parentheses ()
D. The keyword 'begin' and 'end'
Answer: B
Rationale: Python uses consistent indentation (whitespace) to define code blocks,
rather than curly braces or explicit begin/end keywords.
5. What is the correct file extension for a Python script?
.pt
.py
.pyt
.python
Answer: B
Rationale: Python script files conventionally use the .py extension.
6. Which of the following is a valid Python variable name?
A. 2ndvalue
B. my-value
C. _value2
D. class
Answer: C
Rationale: Variable names can start with an underscore or a letter, and can
include numbers after the first character. '2ndvalue' starts with a digit (invalid),
'my-value' contains a hyphen (invalid), and 'class' is a reserved keyword.
7. What will the following code print?
print('Hello,', 'World!')
A. Hello,World!
B. Hello, World!
C. 'Hello,' 'World!'
, D. An error
Answer: B
Rationale: When print() is given multiple arguments separated by commas, it joins
them with a single space by default, producing 'Hello, World!'.
8. Which keyword is used to import a module in Python?
A. include
B. import
C. using
D. require
Answer: B
Rationale: The 'import' keyword is used to bring the contents of a module into the
current namespace, for example: import math.
9. What does the input() function do in Python?
A. Reads a line of text input from the user and returns it as a string
B. Reads a number only
C. Writes text to a file
D. Executes a shell command
Answer: A
Rationale: The input() function pauses program execution, waits for the user to
type text and press Enter, and returns that text as a string.
10. What is the correct way to start a multi-line comment/docstring in Python?
A. Triple quotes: """ """
B. /* */
C. <!-- -->
D. ## ##
Answer: A
Rationale: Triple quotes (either """ or ''') are used to create multi-line strings,
which are commonly used as docstrings or block comments in Python.
11. Which of the following is considered a Python keyword and cannot be used as a
variable name?
A. value
B. total
C. False
, D. number
Answer: C
Rationale: 'False' (along with 'True', 'None', 'if', 'for', etc.) is a reserved Python
keyword and cannot be used as a variable identifier.
12. What is the output of: print(type(5))
A. <class 'str'>
B. <class 'int'>
C. <class 'float'>
D. <class 'number'>
Answer: B
Rationale: The literal 5 is a whole number with no decimal point, so Python
interprets it as an int, and type(5) returns <class 'int'>.
13. Which of the following correctly assigns the value 10 to a variable named x?
A. x = 10
B. x := 10
C. let x = 10
D. int x = 10
Answer: A
Rationale: Python uses a simple equals sign for assignment: x = 10. It does not
require type declarations or special assignment operators for basic assignment.
14. What does the Python interpreter do when it encounters indentation that does
not match the surrounding block?
A. Ignores it silently
B. Raises an IndentationError
C. Automatically corrects it
D. Converts it to a comment
Answer: B
Rationale: Python relies on consistent indentation to define code blocks;
mismatched or inconsistent indentation raises an IndentationError.
15. Which of the following is NOT a valid way to run a Python script named app.py
from the command line?
A. python app.py
B. python3 app.py