From the course: Certified Entry-Level Python Programmer (PCEP-30-02) Cert Prep
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Introduction to exceptions - Python Tutorial
From the course: Certified Entry-Level Python Programmer (PCEP-30-02) Cert Prep
Introduction to exceptions
- [Instructor] While we were coding Python, we have encountered, a couple of times, errors. Those errors where my app crashes actually are known as exceptions. Exceptions are runtime errors that happen when a function can't execute what the code was asking with the current context or the current arguments. For example, you are trying to print something and there is nothing to print. Or you are trying to make a calculation between a number and a Boolean, and that's not possible. You cannot calculate two raised to the power of false, that doesn't make any sense. So that's an exception. In Python, we have different kinds of exceptions and those exceptions have a type. And we can query about the type, so we can know what kind of exception has just happened. For example, we have some exceptions such as IndexError or KeyError, that are being used on lists, tuples, and dictionaries. For example, IndexError can be triggered…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.