Python try…except comma vs 'as' in except

前端 未结 5 969
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 15:14

What is the difference between \',\' and \'as\' in except statements, eg:

try:
    pass
except Exception, exception:
    pass

and:

5条回答
  •  北海茫月
    2020-11-22 15:45

    the "as" syntax is the preferred one going forward, however if your code needs to work with older Python versions (2.6 is the first to support the new one) then you'll need to use the comma syntax.

提交回复
热议问题