0
can we say methods in class as attribute ?
If class and attributes are two different things then how can differentiate each other ?
4 ответов
+ 3
your question and description are quite unclear ^^
did you mean "can we say method in class ARE attributes? how can we differentiate methods from attributes?"
methods are class attributes...
attributes could belong to class and/or instances...
instances first try to access their own attributes, if they don't have such, they try to access class attributes: each having its own namespace, class namespace is shared between instances, but each instance has its own namespace.
methods are functions stored as class attribute, wich got the instance reference (usually called 'self') as first attribute...
along with those, classes could define:
+ properties, wich are methods under the hood, accessed as non callable attributes (getters/setters)
+ behavior for square bracket notation access (through 'magic' methods: double dunder named methods such as __init__)
... differentiate each others could be quite tricky, as much as dynamically than at design time ;P
+ 2
No,
Class attributes are variables of a class that are shared between all of its instances. They differ from instance attributes in that instance attributes are owned by one specific instance of the class only, and are not shared between instances
Regards - Educative.io
+ 2
lisa did I answered / clarified your questions / doubt?
a way to differenciate dynamically a method from an attribute (in the meaning of a non callable attribute) is to use the callable() built-in function:
https://www.geeksforgeeks.org/callable-in-JUMP_LINK__&&__python__&&__JUMP_LINK/
0
visph
did you mean "can we say method in class ARE attributes? how can we differentiate methods from attributes?"
Yes.