Introduction
Setup
Operators
variable
String
Number
Dtype & Comment
Lists
Tuples
Sets
Dictionaries
if else statement
For Loop
While Loop
iterator & iterable
Pre-Built functions
Function
Decorators
Generators
Types of errors
Exceptions Handling
OOP
Regular expression
Create module
OS module
Date module
Random module
Math
Statistics module
Exercise 1
Exercise 2
Exercise 3
Learn Data Structure & Algorithm
Learn Numpy
Learn Pandas
Learn Matplotlib
Learn Seaborn
Learn Statistics
Learn Math
Learn MATLAB
Learn Machine learning
Learn Github
Learn OpenCV
Learn Deep Learning
Learn MySQL
Learn MongoDB
Learn Web scraping
Learn Excel
Learn Power BI
Learn Tableau
Learn Docker
Learn Hadoop
Invalid syntax error raises when we do a mistake to write python syntax.
Example 1:In the example, we don't write colon while creating for loop and it's a syntax mistake. So we get an invalid syntax error.
Example 2:In the example, we don't write colon while creating if condition and it's a syntax mistake. So we get an invalid syntax error.
Suppose we wrote for loop or function or if statement. We know that after the "for" or "if" or "def" declaration line when we wrote the second line then we have to give space before writing the second line. If we forget to give this space then we will get an indentation error.
Example 1:In the example 1, here while creating the for loop we don't space before print function. If we don't do this then it is mistake and we will get indent error.
Example 2:In the example 2, here while creating the if condition we don't space before print function. If we don't do this then it is mistake and we will get indent error.
Suppose we want to print c but we didn't define c. So in this case we will get a name error. So name error occurs when we try to use a thing that is not defined.
Example:In the example, here we didn't create or define c variable and func() function and it is a mistake because if there is not things created then what the print function will print.
Type error occurs when we try to operate with the wrong type. Example: Suppose there two variables and you want to do sum of those values present in the variable. But the data types of those values are string. In this case if you try to summation of those variable values then you will get type error. To avoid the type error at first change the data type of those variable values into integer and then do summation.
In the example, we wanted to addition of a number and string and we got a type error because the type of number is int and the type of string is str.
Index error occurs when we try to perform work with the wrong index.
Example: Suppose you have a list which contain total 5 elements. Now you want to get the last element.
So you write index number 5. But as we know the indexing starts in python from 1 and the last element index
will be 4 but you passed 5. So you will an index error.
Here we have 3 elements in a list. So the index will start from 0 to 2. But we wanted to print 4 index values. Because there is no value at index 4, so we got an index error.
Value error occurs when we write correct data type but pass wrong data type value.
Example:Here we can put string value in s variable. We can also convert string to integer using int function. But we can't convert aaa into integer, so we got value error.
Attributes error occurs when we try to use an attribute that doesn't exist.
Example: Suppose you have a list and you want remove the last value from the end of the list. To do
this you will need pop function. But while using pop function you did a mistake while typing pop. In this you
will get an attribute error.
Here we tried to use a function name push on a list, which doesn't exist. So we got an attribute error.
The key error occurs when we try to use the wrong key which doesn't exist or is defined.
Example:Here we tried to print the price from the dictionary. But there is no key named price. So we got the key error.
In python you can raise your own error. Suppose you think a in your code some where an error can and the error can occur if the user put wrong input. In this you want to show the user a custom error so that the user can understand his or er mistake easily and can put or pass the write value. In these type of situation you can raise you own custom error. Yes, in python you can do this. Now let's see how to show or raise custom error in python.
Example:Here we tried to raise or display the error TypeError.