Python assert(断言)可以分别后面的判断是否正确,如果错误会报错

作用:后面的程序需要依赖前面的条件(可以用if、else代替)

示例:

a = 1
assert type(a) is int
print('No problem')

输出结果:

No problem

a = '1'
assert type(a) is int
print('No problem')

输出结果:

Traceback (most recent call last):
   File "D:/test.py", line 3, in <module>
     assert type(a) is int
AssertionError

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
猜你喜欢
  • 2021-04-09
  • 2022-02-08
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
相关资源
相似解决方案