Home >Backend Development >Python Tutorial >The difference and connection between python3 and python2 exception handling

The difference and connection between python3 and python2 exception handling

WBOY
WBOYOriginal
2016-07-21 14:53:151448browse

In python2.x, exceptions are handled like this. Add a comma "," after the exception base class and then follow the exception type

import traceback

try:
  1/0
except Exception , err:
  print err
 

In python3.x, exceptions are handled like this. The base class connects the exception type through the keyword "as"

import traceback

try:
  1/0
except Exception as err:
  print(err)

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn