Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Treehouse

Object-Oriented Python Course (How To)

via Treehouse

Overview

Sometimes simple scripts with functions in them just aren't enough. Eventually you'll need logical models of your work and that'll lead you to creating custom classes in Python.

Object-oriented programming is a large topic. It provides us some amazing tools, though, so it's one of the most beneficial things to learn about in Python.

First, you'll learn how to build basic custom classes. Then, you'll expand them through inheritance. And for some extra power, you'll also learn how to take control of Python's built-in classes to make your own more powerful while doing less work. Finally, we'll put everything together into a fun game utility.

What you'll learn

  • Object-oriented programming
  • Inheritance
  • Special methods

Syllabus

Instant Objects

What are object/classes in Python and why use them? How do we create instances of classes?

Chevron 12 steps
  • What Are Objects And Classes?

    2:45

  • OOP Vocabulary Quiz 1

    5 questions

  • Let's Make a Class!

    4:21

  • Your first class

    2 objectives

  • Methods

    5:48

  • Your first method

    1 objective

  • Method Arguments

    5:33

  • Method Interactivity

    1 objective

  • __init__

    2 objectives

  • Design

    3:40

  • OOP Basics

    5 questions

  • Master Class

    3 objectives

Inheritance

Classes are great but what if you need a bunch of stuff in common? Python lets us make classes that inherit from each other.

Chevron 7 steps
  • Complex Relationships

    3:37

  • Inheritance Quiz

    5 questions

  • Super-Duper!

    4:36

  • Super!

    3 objectives

  • Multiple Superclasses

    8:31

  • Super

    2 questions

  • Family Tree

    4:50

Advanced Objects

No one wants to create every class from scratch. Let's see how to use Python's classes as the basis of our own.

Chevron 13 steps
  • Controlling Conversion

    6:24

  • Dream Car

    1 objective

  • Math

    6:22

  • Multiplication

    2 objectives

  • Emulating Built-ins

    8:01

  • Iterable Album

    1 objective

  • Subclassing Built-ins

    10:28

  • Double

    3 objectives

  • Frustration

    1 objective

  • Constructicons

    5:26

  • Dream Vacation

    1 objective

  • Special Methods

    7:30

  • Proper Properties

    2 objectives

Dice Roller

Now that we have a good understanding of classes and object-oriented programming, let's use these skills to create a utility we can use when playing games.

Chevron 9 steps
  • Project Breakdown

    5:23

  • Boards

    2 objectives

  • Comparing and Combining Dice

    5:41

  • Compare and Contrast

    1 objective

  • Giving a Hand

    6:07

  • RPG Roller

    2 objectives

  • Yatzy Scoring

    7:42

  • Where to Now?

    1:05

  • Review: Object-Oriented Python

    10 questions

  • Extra Credit

    You can take this project a lot farther! Here are some ideas:

    • Implement a Player class. Give the player a name, a scoresheet, and, on each turn, roll a Hand for them. Let them decide which category to score (only one score per category!). At the end, tell them their cumulative score.
    • Use your Player class to create a ComputerPlayer class. This player is controlled by the program and always scores the highest available score. Let your humans compete against the computer!
    • Keep track of how many times each die has been rolled in a given hand. Dice can be rerolled a maximum three times each before being scored. Give the players a way to reroll their dice.

Reviews

Start your review of Object-Oriented Python Course (How To)

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.