Object Oriented Programming/Classes

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Classes are essentially a giant container for a bunch of functions that can either rely on each other or independently operate within the class. Most classes are made on their own python files and to be used or accessed by other python files. Being a class on its own page allows other python files to call and reference the class without directly affecting the code in the class. Classes can be used for calculating equations, registering user input and acting with it, and raising exceptions to other python files with, again, not being directly affected by other python files' codes.

Subclasses are essentially a child of a Class. Think of Classes as Parents, and Subclasses as Children. Parent Classes can pass properties or functions onto their Child classes. Or think of it as a Child inherits things from their Parent. Subclasses are for more complex programs that utilize multiple ideas under one grand idea.

Below is an example of a Parent class "Tree" with 2 child classes "Birch" and "Oak".

class Tree:

class Birch(Tree):

class Oak(Tree):

See also[edit | edit source]

YouTube Tutorials[edit | edit source]