
Ultimate access to all questions.
A data engineer only wants to execute the final block of a Python program if the Python variable day_of_week is equal to 1 and the Python variable review_period is True. Which of the following control flow statements should the data engineer use to begin this conditionally executed code block?
A
if day_of_week = 1 and review_period:
B
if day_of_week = 1 and review_period = "True":
C
if day_of_week == 1 and review_period == "True":
D
if day_of_week == 1 and review_period:
E
if day_of_week = 1 & review_period: = "True";
Explanation:
The correct answer is D because:
Comparison operator: In Python, to check equality, we use == (double equals) not = (single equals). The single equals = is for assignment, not comparison.
Boolean variable check: When checking if a boolean variable is True, we can simply use the variable name itself in the condition. review_period will evaluate to True if it contains the boolean value True. We don't need to compare it to the string "True" or use == True.
Logical operator: The and operator is the correct way to combine multiple conditions in Python.
Let's analyze each option:
= (assignment) instead of == (comparison)= for assignment and compares review_period to the string "True" instead of checking the boolean valuereview_period to the string "True" instead of checking the boolean value== for comparison and correctly checks the boolean variable= for assignment, & instead of and, and has malformed syntax with : = "True";Key Python concepts:
== for equality comparisonand for logical conjunctionTrue ≠ string "True")