DATABRICKS-CERTIFIED-DATA-ENGINEER-ASSOCIATE · Question #3
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…
The correct answer is D. if day_of_week == 1 and review_period. Python uses '==' for equality comparison, not '=' (which is assignment). Additionally, the variable 'review_period' is already a Boolean (True/False), so it can be used directly in the condition without comparing it to the string 'True'. Answer D ('if day_of_week == 1 and…
Question
Options
- Aif day_of_week = 1 and review_period:
- Bif day_of_week = 1 and review_period = "True":
- Cif day_of_week == 1 and review_period == "True":
- Dif day_of_week == 1 and review_period:
- Eif day_of_week = 1 & review_period: = "True":
How the community answered
(48 responses)- A2% (1)
- C6% (3)
- D88% (42)
- E4% (2)
Explanation
Python uses '==' for equality comparison, not '=' (which is assignment). Additionally, the variable 'review_period' is already a Boolean (True/False), so it can be used directly in the condition without comparing it to the string 'True'. Answer D ('if day_of_week == 1 and review_period:') is correct because it uses '==' to compare the integer, and leverages the boolean truthiness of 'review_period' directly. Comparing a boolean to the string 'True' (as in option C) would evaluate as False because True != 'True' in Python.
Topics
Community Discussion
No community discussion yet for this question.