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
Release: 2016-07-21 14:53:15
Original
1447 people have browsed it

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
 
Copy after login

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)
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template