common errors in python

Опубликовано: 06 Май 2020
на канале: Tarun Sir
788
14

In this video you will learn about some common errors or exceptions in python.

Common errors or exceptions Python
We can face following errors/exceptions in our programs frequently:
1. TypeError : occurs when wrong type applied in an operation.
alist=["Tarun"]
print(sum(alist))#TypeError as sum() function works only with numeric values.

2. ValueError : This error occurs when you give invalid input to casting functions like int() or float(). Consider the following example:

x=int(input("Enter integer : "))#ValueError if you enter non integer.

3. NameError : When we use undefined names in program.
print(x)#if x is not defined earlier

4. ZeroDivisionError : Occurs when we try to divide an integer by 0.
a=10
b=0
c=a/b

5. FileNotFoundError : Occurs when we open a non-existing file in read mode.
reader=open("taruns","r")#FileNotFoundError if taruns file is not found

6. io.UnsupportedOperation: occurs, If you try to write on file, which is opened for reading or vice versa.
xyz=open("test.py","r")
xyz.write("fghf")

7. IndexError : Occurs when we try to use an index that does not exist.
alist=[10]
print(alist[1])
8. KeyError : Occurs when we try to use a key which does not exist.
dic={"tarun":10}
print(dic['arun'])

9. ModuleNotFoundError : occurs when we import a module which does not exist.
import mango #Generates ModuleNotFoundError if mango is not a module

10. ImportError: occurs when we try to import a function which does not exist in a module
from math import cbrt #Throws ImportError as we do not have any cbrt function in math module.

11. KeyboardInterrupt : occurs when we press ctrl+c during the execution of the program.

12. IndentationError : occurs when we use wrong indentation.
alist=[10,20,30,40]
for x in alist:
print(x)
print(x+1)
print("Outside the loop")
The above discussed errors are faced by every beginners. Besides these you can find an official documentation on errors at https://docs.python.org/3.4/library/e...






#python_by_tarun_sir #tarun_sir #python #tarun_sir_python #python_video_61 #common_erros_in_python #python_tutorial #io.UnsupporteOperation_in_python


На этой странице сайта вы можете посмотреть видео онлайн common errors in python длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Tarun Sir 06 Май 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 788 раз и оно понравилось 14 зрителям. Приятного просмотра!