擅长:python、mysql、java
<p>您可以使用扩展的if语句,但我通常更喜欢使用<code>try</code>块。这最终是非常可读的,并且显式地处理<code>TypeErrors</code>,同时还提供了一种相对方便的方法来处理可能出现的其他错误</p>
<pre class="lang-python3 prettyprint-override"><code>try:
if a < b:
do_the_thing()
except TypeError:
handle_bad_types()
</code></pre>