以下是四个简单的assert调用示例:
>>> assert 1==2
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AssertionError
>>> assert 1==2, "hi"
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AssertionError: hi
>>> assert(1==2)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AssertionError
>>> assert(1==2, "hi")
注意,最后一个示例不会引发错误。调用assert时使用或不使用括号会导致这种行为差异,你能解释一下原因吗?我的做法是使用括号,但上述内容表明我不应该这么做。