Python performance: Try-except or not in?

前端 未结 5 786
南笙
南笙 2020-12-19 19:32

In one of my classes I have a number of methods that all draw values from the same dictionaries. However, if one of the methods tries to access a value that isn\'t there, it

5条回答
  •  粉色の甜心
    2020-12-19 20:06

    If it is exceptional, use an exception. If you expect the key to be in there, use try/except, if you don't know whether the key is in there, use not in.

提交回复
热议问题