Reprinted from Https://www.cnblogs.com/JohnABC/p/4065437.htmlLearning Python or other programming languages with abnormal control , it is very possible to say that the execution of try except finally (try Catch finally) is very simple, nothing but
As in other languages, in Python, thetry/except statement is primarily used to handle some exceptions that occur during normal execution of a program , such as syntax errors (Python is not compiled as a scripting language, and syntax is detected
Beginning Python from Novice to Professional, 2nd Edition, CHAPTER 8, EXCEPTIONS, Page 173:
This description in the body:
The point was that using try/except statements are in many cases much more natural (more ' pythonic ') than If/else, and you
An exception occurred while writing the program, and the program may not function correctly. In this case, you need to introduce exception handling1.try ... exceptTry to write the normal running program code, except is the exception condition1 a=3 2
In the execution of the program, it is unavoidable to encounter for some reason, such as the input and output caused by a fatal error (such as because the input file name is wrong, resulting in the inability to run the relevant code. )。 At this
If you are studying python or other programming languages with exception Control, it is very likely that the execution of try catch finally is very simple. If there is an exception, execute retry T, finally is executed regardless of whether there
Town Field Poem:Cheng listens to the Tathagata language, the world name and benefit of Dayton. Be willing to do the Tibetan apostles, the broad show is by Sanfu mention.I would like to do what I learned, to achieve a conscience blog. May all the
1.python try/except/else/finally The normal statement is this:TryNormal Excute blockExcept A:Except A HandleExcept B:Except B HandleExceptOther exception handleElseIf no exception,get hereFinallyPrint (hello World)DescriptionThe normally executed
Illustrate the use of try/except/finally.If you do not use try/except/finally1 ' ABC ' 2 def fetcher (obj, index): 3 return Obj[index] 4 5 fetcher (x, 4)Output: " test.py " in 4) "test.py" in fetcher return obj[index]indexerror:string
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.