Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

How to tell difference between Method and Function when reading someone else's code?

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?
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...
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()


Possibly Related Threads...
Thread / Author Replies Views Last Post
by fomentedSep 8, 2026 06:57 PM 7 150 Sep 8, 2026 06:57 PM
Last Post: Anonynuk
[C] by FhackMar 2, 2022 03:52 AM 4 307 Mar 2, 2022 03:52 AM
Last Post: Fhack
[Java] by SIM-810273Nov 20, 2015 11:51 AM 4 194 Nov 20, 2015 11:51 AM
Last Post: Enchanter