Suppose I have a function with a variable drinks
whose values might be extended later on:
def what_to_drink(drinks):
assert drinks in ['coffee','tea'], "Invalid 'drink' value. Please choose between 'coffee' or 'tea'."
if drinks == 'coffee':
print("I don't drink coffee, I drink tea my dear")
elif: drinks == 'tea':
print("I am an English man in New York")
Since the values for drinks might be extended, it seems to make sense to use elif
instead of else
. However, should the if-statement end with an else-statement? This seems redundant since the assert operator already serves as a gatekeeper for unwanted values. However, without the else-statement, the logic seems incomplete.
Aucun commentaire:
Enregistrer un commentaire