Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Objects...
#1
But x.f is not the same thing as MyClass.f — it is a method object, not a function object.
What is the difference between method and function here, as I learned that method and functions are same things.
Reply
#2
It is very simple, MyClass.f is the function object that was defined in MyClass, while x.f is an entity named 'bound method' which essentialy means a pair containing an instance and a function glued together.
Reply
#3
class MyClass:
    def f():
        pass
The function f() is defined inside the class MyClass and that is the reason to call it method.
Calling the method:

MyClass.f()
Creating an instance of the class:

x = MyClass()
Now, you create an instance of MyClass called x. Then call the method:

x.f()
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I access objects or widgets from one class in another class? Konstantin23 3 1,016 Aug-05-2023, 08:13 PM
Last Post: Konstantin23
  Class objects Python_User 12 4,475 Aug-27-2020, 08:02 PM
Last Post: Python_User
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 2,046 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  printing class properties from numpy.ndarrays of objects pjfarley3 2 1,963 Jun-08-2020, 05:30 AM
Last Post: pjfarley3
  Help with lists and class objects AlluminumFoil 15 5,547 Jan-15-2020, 07:32 PM
Last Post: AlluminumFoil
  How to serialize custom class objects in JSON? Exsul1 4 3,507 Sep-23-2019, 08:27 AM
Last Post: wavic
  How do I write class objects to a file in binary mode? Exsul1 7 5,781 Sep-14-2019, 09:33 PM
Last Post: snippsat
  Do objects get their own copy of the class methods? Charles1 1 2,113 Feb-02-2019, 04:40 PM
Last Post: ichabod801
  AttributeError: 'NoneType' object has no attribute 'n' in list of class objects jdrp 4 5,753 Jun-19-2018, 02:44 PM
Last Post: jdrp
  How to check if class instance exists in a list of class instance objects? sonicblind 23 20,380 May-27-2018, 05:44 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020