Test if a condition returns True:
x = "hello"
#if condition returns True, then nothing happens:
assert x == "hello"
#if condition returns False, AssertionError is raised:
assert x == "goodbye"
Try it Yourself » Definition and UsageThe 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.
More Examples ExampleWrite a message if the condition is False:
x = "welcome"
#if condition returns False, AssertionError is raised:
assert x != "welcome", "x should not be 'welcome'"
Try it Yourself »Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4