Syntax Errors and Exceptions
Learn about syntax errors and exceptions with the coding examples.
We'll cover the following...
Syntax errors
If things go wrong during compilation, the following reasons could be why:
- Something in the program is not written per the Python language guidelines.
Press + to interact
print 'Hello' # ( ) is missing
- The error is reported by the interpreter/compiler.
Press + to interact
b = 2.5d = 'Nagpur'a = b + float(d) # d is a string, so it cannot be converted to float
- A required action is needed to rectify the issue.
Press + to interact
import matha = math.pow(3) # pow( ) needs two arguments
Other common syntax errors are:
- Leaving out a symbol, such as a colon, comma, or brackets.
- Misspelling a keyword.
- Incorrect