🧭Method (Programming)
Also known as Method, Member Function
A function that belongs to an object. It can use that object's data.
Think of it like
Think of it like a trick a pet knows. You say the word, and that pet does its trick.
Example
Lucy calls upper() on the word hello. The string method gives back HELLO, and the original word is unchanged.
Why it matters
Methods keep each action next to the data it works on. That makes code easier to find and change.
Definition
Example code
python
>>> "hello".upper()
'HELLO'Common mistake
Key takeaways
- 1Belongs to an object. A function with a home.
- 2Uses its data. Through self or this.
- 3Called with a dot. Like rex.speak().