A class is a template for objects that each hold their own data. Write one with the class keyword, set an instance up with the __init__() method, and give every instance its own attributes and methods.
No account needed to read a lesson · 30-day money-back guarantee
See the full learning path5
lessons
36
practice questions
81
prerequisite lessons
1 of the 5 lessons here is free to preview - the whole explanation and worked example, with no account and no email.
The editor you get
A still of the editor, not a live one
Python Editor
Editor Output
Output:
Woof
You write and run Python in the browser - nothing to install, no setup. Questions are marked on the values your code produces. The snippet here is an example of the kind of code you write.
The 5 lessons in this unit. Expand any one to see what it covers. Each unlocks when its own prerequisites are passed.
01
Introduction to object-oriented programming
9 questions
Learn how classes define the structure and behaviour of objects in Python, how to create independent instances from a class, and how each instance maintains its own separate state.
Covers
What is a class?
Creating an instance
Instances of a class are independent
02
Custom classes
6 questions
Learn how to define a custom class in Python using the class keyword and apply CamelCase naming conventions to ensure clarity and consistency in your code.
Covers
The class keyword and basic syntax
Naming conventions for classes
03
The __init__() method
9 questions
Learn how Python's __init__() method initialises new class instances, how to pass arguments to customise instance creation, and the role of self in giving access to the object being constructed.
Covers
What is __init__()?
Passing arguments to __init__()
The role of self
04
Instance attributes
6 questions
Learn how to define instance attributes in Python classes by assigning values to self within the __init__() method, and how to access or modify these attributes for each object using dot notation.
Covers
Using arguments in __init__() to define attributes
Accessing and modifying attributes via dot notation
05
Instance methods
6 questions
Learn how to define and use instance methods in Python classes to operate on object data, including how to access attributes with self, pass additional arguments, return values, and call one method from another within the same class.
Covers
What is an instance method?
Working with instance methods
This unit is part of our Python Done Right learning path, which contains 100 lessons. Every one of them is drawn below.
The diagnostic test lets you skip any lesson you already know, including the ones in this unit.
Hover any dot to name its lesson.
5 lessons in this unit
81 prerequisite lessons across the unit, counting every step back to the start
14 other lessons in the learning path - after this unit, or alongside it
Builds on: User-defined functions
One subscription covers every learning path, and you can test out of anything you already know.
One subscription covers every learning path · 30-day money-back guarantee