There are objects in the real world (phone, microphone, popcorn). Objects have attributes (what it is or has; properties) and methods (what it can do). In Python, a class can be used to create an object. A class is a blueprint or template that describes what attributes and methods an object has.
Class: data type, such as int
, string
, function
, or user-defined Car
Object: instantiated class
Method: a function encapsulated within a class, such as the string
class .upper()
method.
Encapsulation: is where data in a class are hidden from other classes and only accessible via the class’s methods (‘data-hiding’); Objects (e.g. Cat) manage their own state/attributes (e.g., energy, age), have private methods (e.g., .meow(), .sleep()) that they can call whenever they want, and can only be touched by other classes via public methods (e.g., .feed()).