- Saved searches
- Use saved searches to filter your results more quickly
- License
- IrvKalb/Object-Oriented-Python-Code
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Object-Oriented Python
- Object-Oriented Python
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Code from Object-Oriented Python
License
IrvKalb/Object-Oriented-Python-Code
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
This repository contains code from the book, «Object-Oriented Python».
Book published in December 2021, published by No Starch Press
Important notice about pygame
As of Python 3.11, a new branch of pygame, named «pygame-ce» (community edition), must be used. (The details of this are too complex to go into here.) In all printings of Object-Oriented Python, there are these installations instructions for the pygame package:
Page 90: Installing the pygame package. The page says to enter these commands at the command line:
python3 -m pip install -U pip --user python3 -m pip install -U pygame --user
To install the community edition of pygame, you must first uninstall the older version of pygame if you have already installed it. Here are the updated commands that you should use at the command line.:
python3 -m pip install -U pip --user python3 -m pip uninstall -U pygame --user python3 -m pip install -U pygame-ce --user
After installing pygame-ce, you do NOT need to change anything to use the example code from the book. In fact, the import statement:
will work to bring in the new pygame-ce package.
I have posted a two-part video on how to make object-oriented buttons in for use in pygame-based programs. You can view them here:
The information in the videos comes from the book.
The documentation for my «pygwidgets» package can be found here:
And the documentation of my «pyghelpers» package can be found here:
Object-Oriented Python
This book is about a software development technique called objectoriented programming (OOP) and how it can be used with Python. Before OOP, programmers used an approach known as procedural programming, also called structured programming, which involves building a set of functions (procedures) and passing data around through calls to those functions. The OOP paradigm gives programmers an efficient way to combine code and data into cohesive units that are often highly reusable.
In preparation for writing this book, I extensively researched existing literature and videos, looking specifically at the approaches taken to explain this important and wide-ranging topic. I found that instructors and writers typically start by defining certain key terms: class, instance variable, method, encapsulation, inheritance, polymorphism, and so on.
While these are all important concepts, and I’ll cover all of them in depth in this book, I’ll begin in a different way: by considering the question, “What problem are we solving?” That is, if OOP is the solution, then what is the problem? To answer this question, I’ll start by presenting a few examples of programs built using procedural programming and identifying complications inherent in this style. Then I’ll show you how an object- oriented approach can make the construction of such programs much easier and the programs themselves more maintainable.
Если вам понравилась эта книга поделитесь ею с друзьями, тем самым вы помогаете нам развиваться и добавлять всё больше интересных и нужным вам книг!
Object-Oriented Python
Object-Oriented Programming (OOP) is a paradigm that combines data and code into cohesive units, allowing you to think differently about computational problems and solve them in a highly reusable way. Aimed at intermediate-level programmers, Object-Oriented Python is a hands-on tutorial that goes deep into the core tenets of OOP, showing you how to use encapsulation, polymorphism, and inheritance to write games and apps using Python.
The book begins by demonstrating key problems inherent in procedural programming, then guides you through the basics of creating classes and objects in Python. You’ll build on this groundwork by developing buttons, text fields, and other GUI elements that are standard in event-driven environments. You’ll also use many real-world code examples and two pygame-based packages to help turn theory into practice, enabling you to easily write interactive games and applications complete with GUI widgets, animations, multiple scenes, and reusable game logic. In the final chapter, you’ll bring it all together by building a fully functional video game that incorporates many of the OOP techniques and GUI elements covered in the book.
- Create and manage multiple objects using an object manager object
- Use encapsulation to hide the inner details of objects from client code
- Use polymorphism to define one interface and implement it in multiple classes
- Apply inheritance to build on existing code
Object-Oriented Python is a visual, intuitive guide to fully understanding how OOP operates and how you can use it to make your code more maintainable, readable, and efficient—without sacrificing functionality.
Irv Kalb is an adjunct professor at UCSC-Extension and University of Silicon Valley (formerly Cogswell College), where he teaches introductory and object-oriented programming courses in Python. Kalb has a bachelor’s and master’s degree in Computer Science, decades of experience developing software while focusing on educational software, and has been teaching for over 10 years. He is the author of Learn to Program with Python 3: A Step-by-Step Guide to Programming (Apress).
Acknowledgments
Introduction
PART I: INTRODUCING OBJECT-ORIENTED PROGRAMMING
Chapter 1: Procedural Python Examples
Chapter 2: Modeling Physical Objects with Object-Oriented Programming
Chapter 3: Mental Models of Objects and the Meaning of “self”
Chapter 4: Managing Multiple Objects
PART II: GRAPHICAL USER INTERFACES WITH PYGAME
Chapter 5: Introduction to Pygame
Chapter 6: Object-Oriented Pygame
Chapter 7: Pygame GUI Widgets
PART III: ENCAPSULATION, POLYMORPHISM, AND INHERITANCE
Chapter 8: Encapsulation
Chapter 9: Polymorphism
Chapter 10: Inheritance
Chapter 11: Managing Memory Used by Objects
PART IV: USING OOP IN GAME DEVELOPMENT
Chapter 12: Card Games
Chapter 13: Timers
Chapter 14: Animation
Chapter 15: Scenes
Chapter 16: Full Game: Dodger
Chapter 17: Design Patterns and Wrap-Up
Index
«If only I could have learned programming with this book! Any sufficiently advanced Python code will work with classes and Irv Kalb has provided a useful, fun introduction to Object-Oriented Programming (OOP). The projects start simple and build upon each other, always with a specific outcome in mind. For example, the first example is a basic card game written in procedural Python. A dozen chapters later, you’ll be including card graphics and keeping track of the state of the deck with OOP concepts like encapsulation, polymorphism, and inheritance—all without reading a dry textbook. Object-Oriented Python is a fun way for new coders to level up their skills.»
— Adam DuVander, EveryDeveloper
«The projects for the most part are real world appropriate, and easily understandable for multiple levels of expertise of the readers . . . Anyone who is interested in learning Python Object Oriented Programming would benefit by having this book in their library. Kudos to both Mr. Kalb and No Starch Press for this book!»
—Full Circle Magazine