Databricks Certified Data Engineer Associate · Free Practice Question Easy
Question 43
-
A
if day_of_week = 1 & review_period: = "True" -
B
if day_of_week = 1 and review_period -
C
if day_of_week == 1 and review_period == "True"
Reveal correct answer
Correct answer:
Explanation
The correct line of code checks if day_of_week equals 1 using double equals == and also checks if review_period is true without comparing it to the string "True". Why?: In Python, to compare values, you should use ==, not =, because = is used for assigning values. The correct option does this by using == to compare day_of_week to 1. It also simply checks if review_period is true, which is the right way to check a boolean (true or false) value in Python. Some incorrect options try to compare a boolean to a string or use assignment operators in a condition, which is not how you write conditions in Python. The best choice directly and correctly checks both conditions without unnecessary comparisons or syntax errors.A. This choice uses the assignment operator '=' instead of the equality operator '=='. It also uses the bitwise AND operator '&' instead of the logical AND operator 'and'. Additionally, the comparison for review_period is incorrect, as it includes unnecessary characters ': = "True"'. These errors make this choice invalid for the given condition.
B. The code uses the assignment operator '=' instead of the equality operator '=='. This will assign the value 1 to day_of_week instead of checking if it is equal to 1. Additionally, the condition for review_period is missing the comparison operator, making this choice incorrect.
C. The code correctly uses the equality operator '==' to compare day_of_week to 1. However, it compares review_period to a string "True" instead of a boolean value True. This will result in a type mismatch and incorrect comparison, making this choice incorrect.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
