Language

Classes & Objects · Lesson 22 of 56

Oops

Source: 8-Class And Objects/8.1-oops.ipynb

Start here — no coding background needed

What you will learn

Intro to classes — templates for objects with data + behavior.

In simple words

A class is a blueprint. An object is one real thing built from it — one student, one bank account.

Think of it like this

Cookie cutter (class) vs each cookie (object).

Group data and actions together — used in bigger apps; go slow, use analogies.

Easy example — try this first

Easy example — run this first. Change values and press Run again.

Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference notes (from full bootcamp)

Optional — deeper detail for when you are ready

Classes and Objects

Object-Oriented Programming (OOP) is a programming paradigm that uses "objects" to design applications and computer programs. OOP allows for modeling real-world scenarios using classes and objects. This lesson covers the basics of creating classes and objects, including instance variables and methods.

Reference example
Python
Output
Expected (from notebook):
<class '__main__.Car'>

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
<__main__.Car object at 0x0000015A0B79FF20>
<__main__.Car object at 0x0000015A0A3374A0>

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
4

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
['__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getstate__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 'doors']

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
<__main__.Dog object at 0x0000015A0B7E99D0>
Buddy
3

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
Lucy
4

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
Buddy says woof
Lucy says woof

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
5000

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
100 is deposited. New balance is 5100

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
300 is withdrawn. New Balance is 4800

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
4800

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Conclusion

Object-Oriented Programming (OOP) allows you to model real-world scenarios using classes and objects. In this lesson, you learned how to create classes and objects, define instance variables and methods, and use them to perform various operations. Understanding these concepts is fundamental to writing effective and maintainable Python code.

Practice test — try yourself

Write code, press Check. Wrong answer shows the correct code to copy & run.

Class Dog with speak() printing Woof!. Create Dog() and call speak().

Python