RS Punia🐍
RS Punia🐍

@CodingMantras

8 Tweets 5 reads Jan 21, 2023
I support: "Python is very easy to start with, but very hard to master."
Even the simple explanation of "Function πŸ†š Method" is not simple enough...
If you consider the below explanation correct and complete, then I insist, check this thread...
πŸ§΅πŸ‘‡
First, let us see the support for the above:
I am not saying it is completely wrong, but it is not complete.
The second explanation, "Functions are function objects, whereas methods are bound methods of a class", looks more technical, so let's cancel it out first.
In the example below:
Both functions appear to be function objects.
For the first explanation, "Functions are defined independently, outside of the class and methods are declared inside the class."
Let's check the example below:
The `greet_outer` is defined outside the class and still can be used as a bound method.
Now the question arises, "Is our explanation given above about `functions and methods` correct completely?"
Let's check what we can add here:
If a function bound to a class is called by an instance of that class and passes that instance, as the first argument to that function, then only that function is called a method of that class instance.
Therefore, function and method are not directly dependent on where they are declared, and a function object can be called a method object by assigning it to a class.
I am still open to the correction of the statement above...
⚑ Thanks for investing your time in this Python Code.
If it helped you, 2 requests:
βœ… Retweet the first tweet so others find it too
βœ… Follow @CodingMantras for more on Python
It encourages me to keep coding and sharing!

Loading suggestions...