self
The name, by convention, of a method's first parameter, which receives the instance the method was called on.
In more detail
dog.speak() is really Dog.speak(dog): Python fills in self for you, which is why it is listed in the definition but not in the call. Instance attributes are reached through it, as self.name.
Related terms
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
- __init__ — The dunder method Python calls to set up a newly created instance, receiving the arguments passed to the class.
- instance attribute — An attribute stored on one instance, usually set as self.name = value, so each instance has its own copy.
Taught in
- The Idle Editor And Running Programs — Hands-on Python: Complete Video Course & Book
- Classes And Instances — Hands-on Python: Complete Video Course & Book
- Methods, Attributes And self — Hands-on Python: Complete Video Course & Book
- Inheritance And Composition — Hands-on Python: Complete Video Course & Book
- Dunder Methods, And Making Objects Pythonic — Hands-on Python: Complete Video Course & Book
- The Class That Shared One List — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Sixty Five Minutes, Forty Items: How PCAP Is Run — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Your Own Modules And Packages — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Classes, Objects And Two Stacks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Class Variables, Instance Variables And __dict__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Methods And The self Parameter — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Introspection: hasattr, __name__, __module__ And __bases__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Inheritance, super() And Polymorphism — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Multiple Inheritance, The MRO And Diamonds — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Special Methods: __str__, __eq__ And Friends — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Object-Oriented Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep