>>> x = 1 >>> y = 2 >>> assert x == y, 'not euqals' Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError: not euqals >>> assert x != y # 这个语句敲下回车不会发生任何问题 >>>
在执行过程中它实际相当于如下代码
1 2 3 4 5 6 7 8 9
>>> x = 1 >>> y = 2 >>> if__debug__andnot x == y: ... raise AssertionError("not equals") ... Traceback (most recent call last): File "<stdin>", line 2, in <module> AssertionError: not equals >>>