Objects [Dec. 21, 2011, 8:31 p.m.]
One of the key aspects of Python is that the language is Object Oriented (OO). The OO paradigm is a conceptual and organizational methodology that we use to create reusable code and develop applications efficiently. Objects are not inherently complex or difficult to work with, in fact, they are simple to create and re-use throught our programming endeavours.
Objects have two main characteristics:
- methods
- attributes
Methods are another word for functions contained within an object. Attributes are variables within an object. Consider a toaster. The toaster has the following function:
>>> toaster.make_toast(bread) # returns toast.
The toaster might have the following attributes:
>>> toaster.color silver >>> toaster.darkness_setting crispy
Notice that the function and attributes are accessed by appending a dot ('.') and the relevant name/function call. This is called, appropriately, 'dot notation' and is designed as a convenience for us programmers.