Example use of assert in Python?

后端 未结 4 2102
庸人自扰
庸人自扰 2021-02-04 12:06

I\'ve read about when to use assert vs. exceptions, but I\'m still not \"getting it\". It seems like whenever I think I\'m in a situation where I should use assert, later on in

4条回答
  •  迷失自我
    2021-02-04 12:48

    Generelly, assert is there to verify an assumption you have about your code, i.e. at that point in time, either the assert succeeds, or your implementation is somehow buggy. An exception is acutally expecting an error to happen and "embracing" it, i.e. allowing you to handle it.

提交回复
热议问题