![]() ![]() It is one of the great utility in python to handle the situation when one exception occurs in an application. In order to handle such unexpected behavior of the application one can use below 2 ways:- 1. Once an exception occurs it leads to crash application unexpectedly. Print("Marks for roll no " + str(n) +" is " +str(marks_list )) Print("Lets Try to find out the result for students in the class") The application is handled in that manner and exits. Once this exception occurs control exits from the main block and enters catch block if any. ![]() We can handle such exceptions using a try-catch block where we can print our own custom error message. In case the index mentioned is not in an integer thus TypeError is thrown. Here, the number of elements in the list are 8 thus n=8 Thus the index for elements are in the range – Īnd in case if one tries to access list2 thus interpreter throws an exception named Inde圎rror with a message that list index is out of range.But in the case while accessing the elements in the list, one mentions the index that is not in the indices range.įor eg – list2 =.Since subscript is of utmost importance while accessing the elements in the list because it makes the process faster and efficient.And if one needs to find the 2 nd element in the list, then we can write list1 That will be Seeta.The indices of elements in the list start from 0 to n-1 where n is the number of elements present in the list. The list is just like an array where elements are accessed using its location in the list. In Python, we have a data structure that Is used to store the elements using the indices, that location of the elements that is the list. Web development, programming languages, Software testing & othersĮxception Inde圎rror How Inde圎rror works in Python? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |