[英]How do you assert something is not true in Python?
在試圖理解Python中的assert
,特別是反轉它時,我想出了這個......
>>> assert != ( 5 > 2 )
>>> assert != ( 2 > 5 )
現在第一行失敗,第二行失敗。 什么是斷言某事的慣用方法是錯誤的?
你使用boolean not
運算符 ,而不是!=
不等式比較運算符:
>>> assert not (5 > 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
>>> assert not (2 > 5)
一個assert
通過測試是否在布爾意義上真正的,所以你需要使用布爾not
操作反轉測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.