Skip to Content
Learning Python, 2nd Edition
book

Learning Python, 2nd Edition

by Mark Lutz, David Ascher
December 2003
Beginner
620 pages
17h 3m
English
O'Reilly Media, Inc.
Content preview from Learning Python, 2nd Edition

Chapter 19. OOP: The Big Picture

So far in this book, we’ve been using the term “object” generically. Really, the code written up to this point has been object-based—we’ve passed objects around, used them in expressions, called their methods, and so on. To qualify as being truly object-oriented (OO), though, objects generally need to also participate in something called an inheritance hierarchy.

This chapter begins the exploration of the Python class—a device used to implement new kinds of objects in Python. Classes are Python’s main object-oriented programming (OOP) tool, so we’ll also look at OOP basics along the way in this part of the book. In Python, classes are created with a new statement: the class. As we’ll see, the objects defined with classes can look a lot like the built-in types we saw earlier in the book. They will also support inheritance—a mechanism of code customization and reuse, above and beyond anything we’ve seen so far.

One note up front: Python OOP is entirely optional, and you don’t need to use classes just to get started. In fact, you can get plenty of work done with simpler constructs such as functions, or even simple top-level script code. But classes turn out to be one of the most useful tools Python provides, and we will show you why here. They’re also employed in popular Python tools like the Tkinter GUI API, so most Python programmers will usually find at least a working knowledge of class basics helpful.

Why Use Classes?

Remember when we told you that ...

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.
Start your free trial

You might also like

Learning Python, 5th Edition

Learning Python, 5th Edition

Mark Lutz

Publisher Resources

ISBN: 0596002815Supplemental ContentErrata Page