python中assert语句

1、assert可以植入程序中进行程序检查

>>> a = 5
>>> b = 3
>>> assert a > 0
>>> assert a < 0
Traceback (most recent call last):
  File "<pyshell#279>", line 1, in <module>
    assert a < 0
AssertionError
>>> assert a > b
>>> assert a < b
Traceback (most recent call last):
  File "<pyshell#281>", line 1, in <module>
    assert a < b
AssertionError
>>> assert a == b
Traceback (most recent call last):
  File "<pyshell#282>", line 1, in <module>
    assert a == b
AssertionError
>>> c = "ABC"
>>> assert c == "ABC"
>>> assert c == "ABD"
Traceback (most recent call last):
  File "<pyshell#285>", line 1, in <module>
    assert c == "ABD"
AssertionError
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14383464.html