INFO1110 Lecture Notes - Lecture 3: Order Of Merit
Document Summary
Typeerror: int() argument must be a string, a bytes-like object or a number, not "list. A valueerror happens when you give the function the right type, but the contents of the type is incorrect. value = int("42b") # we give it a string, but the string value is . Valueerror: invalid literal for int() with base 10: "42b" The following code opens a le that does not exist. A filenotfounderror is raised. f = open("non-existant-file. txt", "r") Filenotfounderror: [errno 2] no such file or directory: "non-existant-file. txt" We can try some code which may not work and catch errors that may occur with the except keyword. try: f = open("non-existant-file. txt", "r") except filenotfounderror: print("the file could not be found. ") Some important points to note: if an exception occurs in a try block, the rest of the block will be ignored, if no exception occurs, all except blocks after the try block are ignored.