Python assert(断言)可以分别后面的判断是否正确,如果错误会报错 示例: a = 1 assert type(a) is int print('No problem') 输出结果: No problem a = ' assert type(a) is int print('No problem') 输出结果: Traceback (most recent call last): File "D:/test.py", line 3, in <module> …
使用assert断言是学习python一个非常好的习惯,python assert 断言句语格式及用法很简单. 用法:在没完善一个程序之前,我们不知道程序在哪里会出错,与其让它在运行时崩溃,不如在出现错误条件时就崩溃,这时候就需要assert断言的帮助. (Assert statements are a convenient way to insert debugging assertions into a program) assert condition 用来让程序测试这个condition…