raise
verb
say it: “RAYZ” /ˈreɪz/
The Python keyword that triggers an exception on purpose, usually when a function is given something it can't work with.
What does raise do?
raise triggers an exception on purpose, usually when your code receives something it can't work with.
def withdraw(balance, amount):
if amount > balance:
raise ValueError("Not enough money in the account")
return balance - amount
In a sentence
- “withdraw() uses raise to stop with a ValueError when the amount is more than the balance.”
- “The test checks that the function will raise an error for a negative price.”
Level: Journeyman · More Python terms at this level
Updated