- 1
Why errors occur in python and what type of errors occur due to what types of mistakes
Pls answer my question
13 ответов
+ 2
A programming language is just an interface to the machine language that the computer understands. So all your code u write is interpreted / compiled depending on language used and turn into machine language 0s and 1s. So if write anything that the computer doesn't understand this causes the error. Take a look at memory of a computer, these are just blocks of 0s and 1s. If u create a list memory is reserved for the list and probably u would get an index error if u try the index the list with a number out of range.
In short, we have syntactical errors (mistyping), exceptions (generated due to uncaught errors)
+ 1
In your code ( never mind youve got them ) is not in quotes thus is not considered as a string and hence generating syntax error.
+ 1
Ok thank you
+ 1
There are mainly two types of errors in Python:
1. Syntax errors
2. Exceptions or runtime errors
1. Syntax errors
Whenever you break a grammar rule while writing your Python code.
For example
Example 1:
int x = 5
Example 2:
print("hello)
Example 3:
if True:
break
Obviously there can be infinitely more examples.
In example 1, error occurs because Python is a dynamically typed language so you can't specify data type.
In example 2, there's an error because you didn't enclose the string within double quotes.
In example 3, error occurs because you can't use a break statement if not within a loop.
2. Exceptions
These are errors that are not because of a grammatical mistake. They can be of many different types like:
ZeroDivisionError
KeyError
ModuleNotFoundError
NameError
ValueError
Are some common exceptions.
Now, as there are too many kinds of exceptions, (ps you can also make your custom exceptions) I can't explain them all. But hopefully I was able to clarify some of your doubts.
Good luck ;)
0
A syntax error occur when you don't type anything according to it's syntax (or the way it should be typed).
0
x = input (" ")
if x = never mind youve got them :
print ("evernay indmay ouyay otgay hemtay")
0
Thanks for your kind information
0
Please share your code here to help us to know your problem to help you .
0
If the code is syntactically wrong then the interpreter will throw a SyntexError.
If you try to divide a number with 0 then it'll throw a ZeroDivisionError.
0
Thanq
- 1
Why does syntax error occor
- 1
And how should I correct it
- 1
Ok should I send my code