Classes and Objects

Everything in python is an object. (Ref: Object Oriented Programming) Objects are an encapsulation of variables, Functions etc into a single entity. Objects get their variables and functions from classes. Classes are a template of your objects. Note: Classes cannot be empty, every class must have at least one object. (use pass if your class is empty).

To assign a class to an object:

object_name = ClassName

Now object_name holds and object of ClassName

To access a variable within a class

Works much like any other variable


To access a function within a class


  • Modules
  • Constructors and Self
    • Remember, a class is a template for an object (Ref; Classes and Objects). You can create many objects, known as instances, from your class. Every time you create an object from a class it will create new Namespaces for that instance. A constructor is responsible for calculating that memory allocated to that instance (() is your constructor) which will call the __init__ method for you. The constructor is called automatically every time you create a new instance.