All exceptions in Python programming language have their own statement (errors/warnings) that are by default returned. We will see one such statement here which is thrown when a TypeError exception occurs.
TypeOf Exception occurs when we put strict constraints over the type of the variable taken in consideration i.e. when the program defines the exact type of data required and it is not entered in that variable. This throws a typeError exception.
Program:
Output:
Explanation:
In the above code, we have created two variables num1 and num2 and taken user input for their values. Both the values entered need to be integer values only. And then we have printed their sum. If the user enters any value other than integer, an exception occurs which is handled using an except block that prints an in-build exception statement.
need an explanation for this answer? contact us directly to get an explanation for this answer