Skip to content

Update python_oop.md#356

Merged
mmcky merged 1 commit into
QuantEcon:mainfrom
jaeyungkim:patch-3
Jun 14, 2025
Merged

Update python_oop.md#356
mmcky merged 1 commit into
QuantEcon:mainfrom
jaeyungkim:patch-3

Conversation

@jaeyungkim

Copy link
Copy Markdown
Contributor

"instance data and functions" together are called attributes, not methods. I believe methods are just the function part.

"instance data and functions" together are called attributes, not methods. I believe methods are just the function part.
@jstac

jstac commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

Thanks @jaeyungkim .

This is indeed completely wrong and we appreciate the fix!

@jstac

jstac commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

@mmcky Could you please merge when ready and perhaps consider republishing?

@mmcky

mmcky commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

thanks @jstac and @jaeyungkim.

I thought that (to be exact) in Python classes

self.example_variable = {{ value }}

is an attribute

while

def function(self, args, kwargs)
    {{ function code }}

is a method.

So classes have both attributes being variables and data and methods being functions.

We could be more precise with the statement for sure (thanks @jaeyungkim) so in my view there is still an error in changing to attributes. I'll propose an update.

Comment thread lectures/python_oop.md
In our example, two functions `earn` and `spend` can be applied to the current instance data.

Taken together, the instance data and functions are called *methods*.
Taken together, the instance data and functions are called *attributes*.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Taken together, the instance data and functions are called *attributes*.
In a Class, the instance data are called *attributes* and functions are called *methods*.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also properties but I don't think we need to mention those.

@jstac

jstac commented Jun 14, 2025

Copy link
Copy Markdown
Contributor

People probably have different opinions here. Google Gemini says the following:

Yes, in Python, a method is an attribute of a class.

To be precise, a method is a callable attribute of a class. Let's break down what this means:

@jstac

jstac commented Jun 14, 2025

Copy link
Copy Markdown
Contributor

Please feel free to make the call @mmcky , I'll leave it with you.

@mmcky

mmcky commented Jun 14, 2025

Copy link
Copy Markdown
Contributor

Thanks @jstac -- interesting. In that case attributes is definitely an improvement. I'll merge this and make live.

@mmcky mmcky merged commit 8973c2e into QuantEcon:main Jun 14, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants