Book Image

Python Fundamentals

By : Ryan Marvin, Mark Nganga, Amos Omondi
Book Image

Python Fundamentals

By: Ryan Marvin, Mark Nganga, Amos Omondi

Overview of this book

After a brief history of Python and key differences between Python 2 and Python 3, you'll understand how Python has been used in applications such as YouTube and Google App Engine. As you work with the language, you'll learn about control statements, delve into controlling program flow and gradually work on more structured programs via functions. As you settle into the Python ecosystem, you'll learn about data structures and study ways to correctly store and represent information. By working through specific examples, you'll learn how Python implements object-oriented programming (OOP) concepts of abstraction, encapsulation of data, inheritance, and polymorphism. You'll be given an overview of how imports, modules, and packages work in Python, how you can handle errors to prevent apps from crashing, as well as file manipulation. By the end of this book, you'll have built up an impressive portfolio of projects and armed yourself with the skills you need to tackle Python projects in the real world.
Table of Contents (12 chapters)
Python Fundamentals
Preface

Built-In Exceptions


Python ships with a ton of built-in exception classes to cover a lot of error situations so that you do not have to define your own. These classes are divided into Base error classes, from which other error classes are defined, and Concrete error classes, which define the exceptions you are more likely to see from time to time.

Note

Built-in exception classes cover many error situations so that you do not have to define your own. For more information on built-in exceptions, visit https://docs.python.org/3/library/exceptions.html.

We shall cover more on the Exception base class and its uses later on in this chapter. For now, let's take a look at some common error and exception classes and understand what they mean.

SyntaxError

A SyntaxError is very common, especially if you are new to Python. It occurs when you type a line of code which the Python interpreter is unable to parse.

Here is an example:

def raise_an_error(error)
    raise error
  
raise_an_error(ValueError)

In this...