Methods and the Object They Operate On
An instance method receives the instance as part of a normal bound call. Its body can read or modify state belonging to that instance.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Trace two calls
If a holds count 2 and b holds count 8, calling a.increment() can add one only to a's count. The method's first parameter traditionally called self in Python refers to a. Parameters and arguments explains how an invocation acquires its bindings.
Test object separation
Construct a second instance before changing the first. Verify both counts afterward. That test catches a shared attribute where the contract promises independent instance state.[1]