Ubuntu Unleashed 2014 Edition: Covering 13.10 and 14.04,Ninth Edition
by Matthew Helmke, Andrew Hudson, Paul Hudson
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access