TL ; DR:
Syntax errors are mistakes in the use of the Python language, analogous to spelling or grammar mistakes in a language like English. For example:
Omitting quotes when working with strings:
print("Welcome!)Omitting parantheses when using the
printfunction:print("Let's code!"When Python encounters a syntax error, it immediately stops executing your code and throws a
SyntaxErrorinstead.
Full lesson:
Humans are prone to making mistakes. Humans are also typically in charge of creating computer programs. To compensate, programming languages attempt to understand and explain mistakes made in their programs.
Here are two common errors that we encounter while writing Python code:
The SyntaxError:
Syntax errors are mistakes in the use of the Python language, and are analogous to spelling or grammar mistakes in a language like English. For example, the sentence "Would you some tea?" does not make sense – it is missing a verb.
SyntaxError means there is something wrong with the way your program is written. Some examples:
1. Misuse of commas when declaring a string:
greeting = 'Hey there!"
2. Leaving out a parantheses:
print"My name is Andy")
When we run any of these programs we'll get a SyntaxError: invalid syntax.
Assignment
Follow the Coding Tutorial and let's practice with errors!
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. Premium is unlimited.
