In this series, we’ll explore Object Oriented Programming.
Everything is an object in Python.
Sometimes the terms objects and classes are mixed, but they are different concepts.
Python Beyond the Basics – Object-Oriented Programming
An object can contain variables and/or methods that interact with those variables.
Sometimes objects are named after real world objects.
In a RC car program, you may find:
servoMotor = Motor()
The first line creates the object. The second line calls the method turnOn(). That method may modify the objects variables.
Objects are not always named after real world objects. In the context of the program, it could even have a one letter name. Consider:
r = Robot()
You may often find other non real-world names. It’s common that applications have some objects that make sense only to coders, like HTTPFetcher or HTMLParser.
An object doesn’t appear out of the blue. It’s created with help of a class. A class is a grouping of methods and variables, sort of an abstract model.
Objects are always created using classes. A class defines an objects methods and variables, but it doesn’t hold the actual variable data.
Objects can be created a runtime – when the program is running. Classes are always defined in the code, before the program starts.