Python study Note 9: exception, python study Note 9:

Source: Internet
Author: User

Python study Note 9: exception, python study Note 9:
I. Syntax

#! /Usr/bin/pythonfilename = 'hello' # try using t finally demotry: open('abc.txt ') print hellospont IOError, msg: print 'The file not exist' handle T NameError, msg: print 'Hello not defined' finally: print 'end' # throw exceptionif filename = "hello": raise TypeError ('Nothing ')
Ii. Common exception types

1. AssertionError: assert statement failed

2. AttributeError: attempts to access a property that is not present in an object

3. IOError: the input and output are abnormal. the file cannot be opened.

4. ImportError: the module or package cannot be introduced, which is basically a path problem.

5. IndentationError: syntax error. The code is not correctly aligned.

6. IndexError: The subscript index exceeds the sequence boundary.

7. KeyError: attempts to access a key that does not exist in your dictionary

8. KeyboardInterrupt: Ctrl + C is pressed

9. NameError: Use a declared variable.

10. SyntaxError: the code logic syntax is incorrect and cannot be executed.

12. TypeError: the input object type does not meet the requirements.

13. UnboundLocalError: Try to ask a global variable that has not been set, basically because there is another global variable with the same name.

14. ValueError: input an unexpected value, even if the type is correct

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.