Errors and Classes for APIs

Errors and Classes for APIs: Handling Errors with try and except, Classes: Blueprints for Your Own Things, Type Hints: Saying What a Value Should Be.

Updated

  1. Handling Errors with try and except (Apprentice): An exception is Python's report of an error while a program runs, and try and except let a program catch the one it expects, such as the ValueError from turning "two" into a number, with else for what runs when nothing went wrong and finally for what runs every time.
  2. Classes: Blueprints for Your Own Things (Apprentice): A class describes one kind of thing your program keeps track of, what it holds and what it can do, so every object made from it gets the same attributes, the same methods and a friendly printout.
  3. Type Hints: Saying What a Value Should Be (Apprentice): A type hint is a label on a variable, a parameter or a return value that says what kind of value belongs there, such as float, list[float] or a string that may be None, so people and tools can see what a function expects without reading its body.