- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between 'except Exception as e' and 'except Exception, e' in Python?
The difference between using ',' and 'as' in except statements, is as follows:
Both ',' and 'as' are same functionality wise; but their use depends on the python versions as follows.
In Python 2.5 and earlier versions, use of the 'comma' is recommended since 'as' isn't supported.
In Python 2.6+ versions, both 'comma' and 'as' can be used. But from Python 3.x, 'as' is required to assign an exception to a variable.
As of Python 2.6 using 'as' allows us an elegant way to catch multiple exceptions in a single except block as shown below
except (Exception1, Exception2) as err
is any day better than
except (Exception1, Exception2), err
Advertisements
To Continue Learning Please Login
Login with Google