Example use of assert in Python?

后端 未结 4 2104
庸人自扰
庸人自扰 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 13:03

    tend to use assert to check for things that should never happen. sort of like a sanity check.

    Another thing to realize is that asserts are removed when optimized:

    The current code generator emits no code for an assert statement when optimization is requested at compile time.

提交回复
热议问题