Python is a very object-oriented language, which makes it easy to work with. For those of you who may not be familiar with the concept of object-oriented programming languages, Peyton provides a complete, easy-to-understand explanation, and then gives a number of examples that illustrate how object orientation works in Python.
print parentObject.testMethod ( 'This is a long string.' ) # "22"
print childObject.testMethod ( 'This is a long string.' ) # "22 ( Extra Stuff )"
It is also possible to create a subclass with multiple parents:
testVariableA = "This is another test. In fact, this is the last one."
testVariableB = "Caffeine fuels the world."
def testMethodA ( self ):
def testMethodB ( self ):
class ChildClass ( ParentClassOne, ParentClassTwo, ParentClassThree ):
anObject = ChildClass()
print anObject.testVariableA # "This is another test. In fact, this is the last one."
print anObject.testVariableB # "Caffeine fuels the world."
print anObject.testMethodA() # True
print anObject.testMethodB() # False
As you've witnessed, Python itself is unbelievably object-oriented, and it supports both simple and complex object-oriented design. While scripting in Python, you will come across object orientation regularly. When you create a string, you are creating an object. When you work with files, you are working with objects as well. When you work with Python's extensive standard library, you are, again, working with objects. Objects make Python an incredibly easy language to work with.
You now understand the basics of objects and object-oriented programming. You may now utilize your knowledge in your scripts, potentially simplifying the development process.