Welcome To
Errors


Errors In Python

The error in python that code can have some problem to execute . it means the python interpreter cannot understand by your code to execute . in that time the python interpreter shows error message . and error can occur variety of reasons like invalid syntax, unexpected spaces and invalid input.

Types Of Errors

  1. Syntax Error
  2. Runtime Error
  3. Logical Error

Let us see the meaning of each type..

Syntax Error

It is a one type of error occur during the program execution time . the program code violence the rules of python. in the that time the python interpreter shows syntax error. The python unable to understand the the that line of code due to incorrect syntax. The Syntax error is also known as a parsing error. the incorrect syntax cause it to crash the execution of a program. Examples in the below

Examples

Print("Hello,Darshan"
# in above code is cause error because missing closing parenthesis

Error Message

SyntaxError: '(' was never closed
This error is

Logical Error

The Logical Error also one type of error in the python .the code can execute successfully but the the result is not correct unexpected result. this type of error is most difficult to debug becuse that interpreter does not show the error message.and this type of error in variety of reasons like , incorrect operator and function , missing control flow statements in the python code Examples in the below

Examples

def add_numbers(a,b):
      return a-b
print(add_number(10,20))
output is wrong. we want to add number but here operator change. + instead of - The code can execute successfully but the expected

Runtime Error

It is a most important Error in the python code because you had experience in this. The Run time errors occur during the run time or program Execution Error. the list of errors and examples in the below. the error like ZeroDivisionError,NameError,TypeError,KeyError,IndexError and more

Let us discus the types of errors in the runtime

ZeroDivisionError

The Error is occur during the runtime. The Python Interpreter does not divide the zero by any integer. in that time the python interpreter shows an ZeroDivisionError Example in the below.

Examples

print(10/0)

Error Message

ZeroDivisionError: division by zero

NameError

The name error is a one type of runtime error. undefined variable in the program. you wants to print the using the undefined variable

Example

name="Darshan"
print(Name)# the variable the first letter is caps using

Error Message

NameError: name 'Name' is not defined. Did you mean: 'name'?

TypeError

The error is invalid datatype error by using int to string

Example

x=darshan
print(x)

Error Message

NameError: name 'darshan' is not defined

IndexError

Accessing invalid index to non exist item in the list. Example in the below

Example

list=[1,2,3,4,5]
print(set[5])

Error Message

IndexError: list index out of range

KeyError

The error occur the accessing the non exist key in dictionary. Example in the below

Example

dict={
"name":"darshan",
"age":19,
"place":"kolar"
}
Print(f"The key"{key})

Error Message

keyError:undefined key