Anonymous contributor85 contributions
Published Apr 12, 2022
Contribute to Docs
A keyword for confirming the truthiness of a given statement that is often used to facilitate development, document code, and debug.
assert some_condition, assert_message
assert keyword is followed by
some_condition to be tested, such as validating a data type or membership within a given container. An optional
assert_message can be added that will be printed when the assertion error is raised.
assert keyword can be used to validate a value (or evaluate some other condition):
fav_color = 'blue'assert fav_color == 'red'# Output: AssertionError
The following example uses
assert to evaluate if ‘mud’ is within the following list
- Anonymous contributorAnonymous contributor85 contributions
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification