Skip to main content
Loading page…
Python Mastery
Chapter 12
Lesson 2 of 4
Attributes, Methods & Encapsulation
Contents
Notes
Tutor
Concept
Class Attributes vs Instance Attributes
Loading activity…
Previous
1 / 8
Continue
Contents
Notes
Discussion
Tutor
25 min
8 activities
0 of 8 done
In this lesson
1
Class Attributes vs Instance Attributes
2
Encapsulation with _ and __ Prefixes
3
Methods That Mutate State and Keep Invariants
4
Class vs Instance Attribute Mutation
5
Match the Convention to Its Meaning
6
Warning: Don't Over-Privatise
7
Add a Transaction History to BankAccount
8
Pro Tip: Properties Are the Pythonic Getter/Setter
Objectives
Distinguish class attributes (shared) from instance attributes (per-object)
Apply the _single-underscore and __double-underscore naming conventions for encapsulation
Write methods that safely mutate state while keeping class invariants
Explain when name-mangling applies and why it exists
Chapter 12 · Object-Oriented Programming
Classes & Instances
Attributes, Methods & Encapsulation
Inheritance & super()
Designing with Objects
Previous: Classes & Instances
Next: Inheritance & super()