Mission 352 Object Oriented Python Takeaways
Mission 352 Object Oriented Python Takeaways
Syntax
• Define an empty class:
class MyClass:
pass
pass
mc_1 = MyClass()
self.attribute_1 = param_1
mc_2 = MyClass("arg_1")
self.attribute_1 = param_1
def add_20(self):
self.attribute_1 += 20
Concepts
• In Object-Oriented Programming, the fundamental building blocks are objects.
• It differs from Procedural programming, which executes sequential steps.
• An object is an entity that stores data.
• A class describes an object's type. It defines the following:
• What data is stored in the object, known as attributes
• What actions the object can do, known as methods
• An attribute is a variable that belongs to an instance of a class.
• A method is a function that belongs to an instance of a class.
• We access attributes and methods using dot notation. Attributes do not use parentheses,
whereas methods do.
• The init method is a special method that runs at the moment of an object's instantiation.
• The init method ( __init__() ) is one of a number of special methods that Python defines.
• All methods must include self , representing the object instance, as their first parameter.
• It is convention to start the name of any attributes or methods that we don't intend for external
use with an underscore.
Resources
• Python Documentation: Classes