python with assert code example
Example 1: assert syntax python
assert <condition>,<error message>
#The assert condition must always be True, else it will stop execution and return the error message in the second argument
assert 1==2 , "Not True" #returns 'Not True' as Assertion Error.
Example 2: assert keyword in python
The assert keyword is used when debugging code.
The assert keyword lets you test if a condition in your code returns
True, if not, the program will raise an AssertionError.
You can write a message to be written if the code returns False, check
the example below.
x = "hello"
#if condition returns False, AssertionError is raised:
assert x == "goodbye", "x should be 'hello'"