Skip to content
dreamcode
dreamcode
Map
OOP
Lesson 44 of 77
+15 XP on finish
PYTHON INTERMEDIATEChapter 8 · Objects and Classes

Object-oriented programming

Python supports Object-Oriented Programming (OOP). Define a class using class, and initialize fields inside __init__(self).

Worked example

How it reads

  • def __init__(self, name) defines the constructor method
  • self refers to the specific instance of the object class
Cloud tip: Methods must receive self as their first parameter to access object fields.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Add a method describe(self) that returns "A cumulus cloud" built from self.shape, and print c.describe().

Press Run to check your work.