assert expression in Python

tags:

1. synatx

1
2
3
4
assert [expression]
# it is same with
if not [expression]:
raise AssertionError

2. with parameters

1
2
3
4
assert expression [, arguments]
# same with
if not expression:
raise AssertionError(arguments)

conclusion

if an assert is not satisfied, throw exception. easy to detect the errors in code.