Python assert keyword
উদাহরণ
Test if the condition returns True:
x = "hello" # If the condition returns True, nothing will happen: assert x == "hello" # If the condition returns False, it will raise AssertionError: assert x == "goodbye"
Definition and Usage
assert keyword is used when debugging code.
assert keyword allows you to test if the condition in the code returns True, otherwise, the program will raise AssertionError.
You can write a message that will be output if the code returns False, see the following example.
আরও উদাহরণ
উদাহরণ
If the condition is False, write a message:
x = "hello" # How to conditionally return False, raise AssertionError: assert x == "goodbye", "x should be 'hello'"