Skip to ContentGo to accessibility page
Introduction to Python Programming

11.1 Object-oriented programming basics

Introduction to Python Programming11.1 Object-oriented programming basics

11.1 Object-oriented programming basics

Learning objectives

By the end of this section you should be able to

  • Describe the paradigm of object-oriented programming (OOP).
  • Describe the concepts of encapsulation and abstraction as they relate to OOP, and identify the value of each concept.

Grouping into objects

Object-oriented programming (OOP) is a style of programming that groups related fields, or data members, and procedures into objects. Real-world entities are modeled as individual objects that interact with each other. Ex: A social media account can follow other accounts, and accounts can send messages to each other. An account can be modeled as an object in a program.

Checkpoint

Using objects to model social media

Using objects to model social media; ch 11, video 1

Concepts in Practice

OOP

1.
Consider the example above. Which is a field in Ellis's 12/18/23 post?
  1. Ellis's followers list
  2. Ellis's username
2.
What does an object typically model in object-oriented programming?
  1. program code
  2. real-world entity

Encapsulation

Encapsulation is a key concept in OOP that involves wrapping data and procedures that operate on that data into a single unit. Access to the unit's data is restricted to prevent other units from directly modifying the data. Ex: A ticket website manages all transactions for a concert, keeping track of tickets sold and tickets still available to avoid accidental overbooking.

Checkpoint

Encapsulating concert ticket information

Encapsulating concert ticket information; ch 11, video 2

Concepts in Practice

Encapsulation

3.
Consider the example above. Suppose the venue has to be changed due to inclement weather. How should a programmer change the website object to allow changes to the Venue field?
  1. Add a procedure to change the field.
  2. Allow users direct access to the field.
  3. No valid way to allow changes to the field.
4.
Which is a benefit of encapsulation when developing complex programs?
  1. All objects can easily access and modify each other's data.
  2. Each object's data is restricted for intentional access.

Abstraction

Abstraction is a key concept in OOP in which a unit's inner workings are hidden from users and other units that don't need to know the inner workings. Ex: A driver doesn't usually need to know their car engine's exact, numerical temperature. So the car has a gauge to display whether the engine temperature is within an appropriate range.

Checkpoint

Abstracting data in a countdown calculator

Abstracting data in a countdown calculator; ch 11, video 3

Concepts in Practice

Abstraction

5.
Consider the car example in the paragraph above. Suppose the designer decided to remove the engine temperature indicator. Would this be a good use of abstraction?
  1. yes
  2. no
6.
Which is a benefit of abstraction?
  1. improved view of information
  2. high visibility of information
Citation/Attribution
Reuse and redistribution of this content in digital or print format:
  • This book may not be used in the training of large language models or otherwise be ingested into large language models or generative AI offerings without OpenStax's prior written permission.
  • This book uses the Creative Commons Attribution-NonCommercial-ShareAlike License, which means that you can reuse and modify the material only for noncommercial purposes, must attribute OpenStax, and must distribute any derivative works under the same license.
  • Any commercial printing of this textbook, including using a local or custom printer, must be approved by OpenStax, and proper citation provided.
  • OpenStax-copyrighted images, activities, assessments, and similar components of this book are subject to the same licensing – CC-BY-NC-SA. They can be used for noncommercial purposes with attribution. Commercial use requires permission.
  • Permission requests: Anyone who intends to incorporate this content (including text, images, and other components) into large language models, use it in AI offerings, use it commercially (including in print), and/or has questions about another use case is welcome to complete our reuse request form.
Attribution information
  • If you are redistributing all or part of this book in a noncommercial print format, then you must include on every physical page the following attribution:

    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction

  • If you are redistributing all or part of this book in a noncommercial digital format, then for every page that includes OpenStax content, you must license the derivative work under the same CC-BY-NC-SA license as the original, and include on every digital page view the following attribution:

    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction

Citation information

The information below includes the information needed to generate citations in most major styles (APA, MLA, etc.); you must reformat and organize the information as needed to fit the requirements of the style. Use the information below to generate a citation. We recommend using a citation tool such as this one.

© Apr 23, 2026 OpenStax. Textbook content produced by OpenStax is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike License. The OpenStax name, OpenStax logo, OpenStax book covers, OpenStax CNX name, and OpenStax CNX logo, and Rice University name, and Rice University logo trademarks, or wordmarks are not subject to the Creative Commons license and may not be reproduced without the prior and express written consent of Rice University.

This book utilizes the OpenStax Python Code Runner. The code runner is developed by Wiley and is All Rights Reserved.