Object Orientation
After having read this far, you should not be surprised to hear that Python’s object orientation is flexible and likely to surprise you if you have been using C-like languages for several years.
The best way to learn Python object-oriented programming (OOP)
is to just do it. So, here is a basic script that defines a class, creates an object of that class, and calls a function:
class Dog(object): def bark(self): print "Woof!"fluffy = Dog()fluffy.bark()
Defining a class starts, predictably, with the class
keyword followed by the name of the class you are defining and a colon. The contents of that class need to be indented one level so that Python knows where it stops. Note that the object inside parentheses is there ...
Get Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.