先打开相应的配置面板,有以下两种方式. 然后在VM栏里输入 -enableassertions 或者 -ea 就好了 然后编写程序试试 我的目录结构如下:(因为Main class那里要写类的全限定名, -ea的上一行) 代码: public class AssertTest { public static void main(String[] args) { int a = 10; int b = 20; assert a > b : "错误,a不大于b"; } } 结果:…
一.python assert的作用: 根据Python 官方文档解释(https://docs.python.org/3/reference/simple_stmts.html#assert), "Assert statements are a convenient way to insert debugging assertions into a program". 二.一般的用法是: assert condition 用来让程序测试这个condition,如果condition为…