Your code will break. Everyone's does, every day, including people who have written Python for twenty years. An error is not a telling-off. It is Python trying to help, and learning to read what it says is one of the most useful things you can pick up early.
Reading the message
When something goes wrong, Python prints a block of text called a traceback. It can look intimidating. The trick is that the last line is the important one — it tells you what went wrong. The lines above it tell you where.
print('Hello)Run that and Python says something like:
Read it backwards. SyntaxError means Python could not even understand the line, usually a missing quote or bracket. It even tells you the line number.
SyntaxError: unterminated string literal (detected at line 1)Read it backwards. SyntaxError means Python could not even understand the line, usually a missing quote or bracket. It even tells you the line number.
The three you will meet first
SyntaxError — Python cannot understand your code. Nearly always a missing quote, a missing bracket, or a missing colon.
NameError — you used a name Python has never seen. Usually a typo, like writing
TypeError — you asked for something that does not make sense for that kind of value, like adding a number to a piece of text.
NameError — you used a name Python has never seen. Usually a typo, like writing
primt instead of print.TypeError — you asked for something that does not make sense for that kind of value, like adding a number to a piece of text.
primt('Hello')
# NameError: name 'primt' is not defined