Key Concepts

Review core concepts you need to learn to master this subject


age = 7 + 5 = 4 File "<stdin>", line 1 SyntaxError: can't assign to operator

A SyntaxError is reported by the Python interpreter when some portion of the code is incorrect. This can include misspelled keywords, missing or too many brackets or parenthesis, incorrect operators, missing or too many quotation marks, or other conditions.

Lesson 1 of 2
  1. 1
    It is truly an amazing feeling when our code works exactly the way we want it to. On the other hand, it can be equally frustrating when our code runs into errors. Since errors are such an integral …
  2. 2
    In the previous exercise (and probably many times before), we saw one type of exception called the NameError. The NameError is just one of the many built-in exceptions - exceptions that are built…
  3. 3
    Encountering exceptions isn’t always an accident. We can throw an exception at any time by using the raise keyword, even when Python would not normally throw it. We might want to raise an exceptio…
  4. 4
    So far, the exceptions we’ve encountered have caused our programs to stop executing. However, it is possible for programs to continue executing even after encountering an exception. This process is…
  5. 5
    The exception handlers from the previous exercise handled any exception hit during the try clause. However, in most cases, we will have an idea of the types of exceptions that might occur within ou…
  6. 6
    While handling a single exception is useful, Python also gives us the ability to handle multiple exceptions at once. We can list more than one exception type in a tuple with a single except clause….
  7. 7
    We’ve seen how exception handlers get executed when we encounter exceptions during a try clause - but what if we want to run some code only if we do not encounter an exception? Python provides us a…
  8. 8
    With try/except/else, we’ve seen how to run certain code when an exception occurs and other code when it does not. There is also a way to execute code regardless of whether an exception occurs - th…
  9. 9
    So far we have seen how to raise and manage built-in exceptions. In most programs, using built-in exceptions won’t always be the most detailed way to describe an error occurring. What if we could c…
  10. 10
    We’ve just seen how defining a simple exception class can provide a more specific and useful error to users. Defining a simple class is just the first step to creating better exceptions in our prog…
  11. 11
    Congratulations, you have now mastered many techniques for interacting with exceptions in Python! We learned: * How exceptions differ from syntax errors * How to read tracebacks * How try/except/el…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo