Hack Forums
[Python] How to tell difference between Method and Function when reading someone else's code? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] How to tell difference between Method and Function when reading someone else's code? (/showthread.php?tid=5961699)



How to tell difference between Method and Function when reading someone else's code? - Lindros - Apr 18, 2019

I know the difference between a method and a function is that a method is declared inside a class. My only question is that how can I tell the difference when reading python code.

Say there is an object.something()

How do I know if "something" is a function or a method being called? Does it matter? Do I just command click and see if it is declared in a class? (using MacOS).

Is everything using a "." like "variable.something" now a method regardless of if it was defined as a method or function?

Am I missing something? I feel like there should be an easier way.. Or does it not matter?


RE: How to tell difference between Method and Function when reading someone else's code? - loomski - Apr 18, 2019

You use a method if you're trying to return something or call something from a class...

You use a function if it's not a part of a class...

I don't understand your question. If variable isn't a class, how can you call variable.something? lol I'm sorry, I've been coding in Python for 2 years now, 8 months professionally and I'm having a hard time understanding what you're asking...


RE: How to tell difference between Method and Function when reading someone else's code? - .kr. - Apr 19, 2019

this is a method call:
Code
object = Object()
object.method()

and this is a (static) function call. it don't use a instance of your class:
Code
Object.function()