WGU D335 Intro to Python | OA | Objective
Assessment | 15 Actual Questions and
Answers | 2025 Update | 100% Correct.
Section 1: Python Basics & Syntax
Q1. Which of the following is the correct way to write a single-line comment in Python?
A. // This is a comment
B. <!-- This is a comment -->
C. # This is a comment
D. /* This is a comment */
Correct Answer: C
Rationale: Python uses the # symbol for single-line comments. Option A is C/Java style, B is
HTML, and D is C/Java block comment syntax. Python has no true multi-line comment token;
triple-quoted strings are often used as a workaround.
Q2. What is the output of the following code?
python
print(type(3.14))
A. <class 'int'>
B. <class 'float'>
C. <class 'double'>
D. <class 'decimal'>
Correct Answer: B
Rationale: Any numeric literal containing a decimal point is a float in Python. Python has no
double type. int would be for whole numbers like 3.
Q3. Which of the following are valid Python variable names? (Select all that apply.)
A. 2nd_place
B. _total
,C. my-var
D. studentName
E. class
Correct Answers: B, D
Rationale: Variable names may contain letters, digits, and underscores but cannot start with
a digit (A is invalid), cannot contain hyphens (C is invalid), and cannot be reserved keywords like
class (E is invalid). _total and studentName are both valid.
Q4. What is the output of print("Hello" + " " + "World")?
A. Hello World
B. HelloWorld
C. Hello+World
D. Error
Correct Answer: A
Rationale: The + operator concatenates strings. With the explicit space " " in the middle, the
result is Hello World.
Q5. Which statement about Python indentation is TRUE?
A. Indentation is optional and only for readability.
B. Indentation defines code blocks and must be consistent.
C. Python requires tabs, never spaces.
D. Indentation must be exactly 2 spaces.
Correct Answer: B
Rationale: Unlike many languages, Python uses indentation to define blocks (loops,
functions, conditionals). Mixing tabs and spaces or inconsistent indentation raises
IndentationError or TabError.
Q6. What does print(len("Python")) output?
A. 5
B. 6
C. 7
D. Error
, Correct Answer: B
Rationale: "Python" has six characters: P-y-t-h-o-n. len() returns the number of characters in
the string.
Q7. Which of the following are Python keywords? (Select all that apply.)
A. def
B. print
C. lambda
D. main
E. None
Correct Answers: A, C, E
Rationale: def, lambda, and None are reserved keywords. print is a built-in function (not a
keyword), and main is just an ordinary identifier.
Q8. What is the correct file extension for a Python source file?
A. .py
B. .pt
C. .pyt
D. .python
Correct Answer: A
Rationale: Python source files use .py. Compiled bytecode uses .pyc, but source code is .py.
Q9. What is the output?
python
x = 10
y=3
print(x // y)
A. 3.33
B. 3
, C. 4
D. 1
Correct Answer: B
Rationale: // is floor division. 10 // 3 = 3 (the decimal portion is discarded, not rounded). 10
% 3 would be 1.
Q10. Which of these is the correct syntax to define a function?
A. function myFunc():
B. def myFunc():
C. define myFunc():
D. func myFunc():
Correct Answer: B
Rationale: Python uses the def keyword followed by the function name, parentheses, and a
colon.
Q11. What does print(bool("")) output?
A. True
B. False
C. None
D. Error
Correct Answer: B
Rationale: An empty string is "falsy" in Python. Any non-empty string (even " " or "False") is
truthy.
Q12. Which of the following will raise an error?
A. x = "5" + "5"
B. x = 5 + 5
C. x = "5" + 5
D. x = 5 * 2
Assessment | 15 Actual Questions and
Answers | 2025 Update | 100% Correct.
Section 1: Python Basics & Syntax
Q1. Which of the following is the correct way to write a single-line comment in Python?
A. // This is a comment
B. <!-- This is a comment -->
C. # This is a comment
D. /* This is a comment */
Correct Answer: C
Rationale: Python uses the # symbol for single-line comments. Option A is C/Java style, B is
HTML, and D is C/Java block comment syntax. Python has no true multi-line comment token;
triple-quoted strings are often used as a workaround.
Q2. What is the output of the following code?
python
print(type(3.14))
A. <class 'int'>
B. <class 'float'>
C. <class 'double'>
D. <class 'decimal'>
Correct Answer: B
Rationale: Any numeric literal containing a decimal point is a float in Python. Python has no
double type. int would be for whole numbers like 3.
Q3. Which of the following are valid Python variable names? (Select all that apply.)
A. 2nd_place
B. _total
,C. my-var
D. studentName
E. class
Correct Answers: B, D
Rationale: Variable names may contain letters, digits, and underscores but cannot start with
a digit (A is invalid), cannot contain hyphens (C is invalid), and cannot be reserved keywords like
class (E is invalid). _total and studentName are both valid.
Q4. What is the output of print("Hello" + " " + "World")?
A. Hello World
B. HelloWorld
C. Hello+World
D. Error
Correct Answer: A
Rationale: The + operator concatenates strings. With the explicit space " " in the middle, the
result is Hello World.
Q5. Which statement about Python indentation is TRUE?
A. Indentation is optional and only for readability.
B. Indentation defines code blocks and must be consistent.
C. Python requires tabs, never spaces.
D. Indentation must be exactly 2 spaces.
Correct Answer: B
Rationale: Unlike many languages, Python uses indentation to define blocks (loops,
functions, conditionals). Mixing tabs and spaces or inconsistent indentation raises
IndentationError or TabError.
Q6. What does print(len("Python")) output?
A. 5
B. 6
C. 7
D. Error
, Correct Answer: B
Rationale: "Python" has six characters: P-y-t-h-o-n. len() returns the number of characters in
the string.
Q7. Which of the following are Python keywords? (Select all that apply.)
A. def
B. print
C. lambda
D. main
E. None
Correct Answers: A, C, E
Rationale: def, lambda, and None are reserved keywords. print is a built-in function (not a
keyword), and main is just an ordinary identifier.
Q8. What is the correct file extension for a Python source file?
A. .py
B. .pt
C. .pyt
D. .python
Correct Answer: A
Rationale: Python source files use .py. Compiled bytecode uses .pyc, but source code is .py.
Q9. What is the output?
python
x = 10
y=3
print(x // y)
A. 3.33
B. 3
, C. 4
D. 1
Correct Answer: B
Rationale: // is floor division. 10 // 3 = 3 (the decimal portion is discarded, not rounded). 10
% 3 would be 1.
Q10. Which of these is the correct syntax to define a function?
A. function myFunc():
B. def myFunc():
C. define myFunc():
D. func myFunc():
Correct Answer: B
Rationale: Python uses the def keyword followed by the function name, parentheses, and a
colon.
Q11. What does print(bool("")) output?
A. True
B. False
C. None
D. Error
Correct Answer: B
Rationale: An empty string is "falsy" in Python. Any non-empty string (even " " or "False") is
truthy.
Q12. Which of the following will raise an error?
A. x = "5" + "5"
B. x = 5 + 5
C. x = "5" + 5
D. x = 5 * 2