Basic Errors in python

      A successful developer needs to know how to handle the errors. In python, basic errors are listed below.

  1. ·       Indentation error.
  2. ·       Syntax error
  3. ·       Type error
  4. ·       Name error  

1.Indentation error:

Python follows indentation properly.

Let a is assigned to 7 and b is assigned to 4. Just check if a is greater than b, print a.

Here, if statement and its block is in same indentation. In python, it is an indentation error.


Let us rewrite the code with proper indentation.

 2.Syntax error:

           This error comes when the user misses the syntax. The below example, user missed colon(:) in the while loop.

Let we correct the error putting : after the while loop condition. Here, is the outcome.

3.Type error:

         This error occurs, when the user wrongly uses the datatype. Instead of int datatype , somebody used char datatype. Example is given below.

Note: use proper datatype.

The error is corrected below.

4.Divide by zero error:

           This is the very common error. Let us, code an example below.

Just change the code by z = y/2 or any number.

These are the basic errors in python.

No comments:

Post a Comment