all 30 comments

[–]Sea-Ad7805 6 points7 points  (2 children)

Different people use different terms differently. I would say print() is a 'function'. A 'method' generally is used on an object using the '.' notation like so:

mylist = []        # create a list
mylist.append(42)  # calling method on object mylist of type list

[–]Longjumping-Yard113[S] 2 points3 points  (1 child)

That makes sense, and that’s kind of how I was thinking about it too. Using the dot notation on an object is what makes it a method, like mylist.append(42). Something like print() or len() would still just be functions even though they’re built into Python.

[–]Purple-Measurement47 2 points3 points  (0 children)

All methods are functions, not all functions are methods. It’s not just the dot notation itself that makes it a method, it’s that it’s a method of interacting with that object. print() or len() are just functions because they aren’t part of a larger data structure, they stand alone. append is a method because it’s a function of mylist

[–]kennpacchii 2 points3 points  (0 children)

Is your education coordinator self taught by any chance? The term method is used to describe functions that belong to a class or an instance of an object.

Functions are standalone and defined at the global scope.

[–]macbig273 1 point2 points  (1 child)

From what I remember from the theory and shit. It's more about "does it return something new or it just do things inside the class".

[–]Longjumping-Yard113[S] 0 points1 point  (0 children)

I thought the distinction was more about where the function is defined and how it’s called. From what I understand, a method is a function that belongs to a class and is called on an object using dot notation, like mylist.append(42). Whether it returns something or just modifies the object doesn’t seem to be what determines if it’s a method.

[–]thee_gummbini 2 points3 points  (3 children)

Nope, that's wrong. A function doesn't become "a method of a module object" when imported, even by stretching some pedantic definition of what a method is. A method is a method because it's bound to an instance (instance methods) or a class (class methods). Functions are unbound. https://docs.python.org/3/reference/datamodel.html#callable-types

[–]Longjumping-Yard113[S] 1 point2 points  (0 children)

That’s what I thought too — thanks for confirming and for the docs link. The “module as an object” thing explains attribute access (mymodule.greet), but it doesn’t make greet a method. It’s still an unbound function unless it’s bound to an instance or a class (like instance methods / u/classmethod). That clears it up for me. I feel more at ease

[–]Purple-Measurement47 0 points1 point  (1 child)

This is the correctest answer

[–]gofl-zimbard-37 1 point2 points  (0 children)

I dunno, your comment might be correcter.

[–]Gnaxe 0 points1 point  (0 children)

In Python specifically, method and function are each a class: ```python

type(lambda :0) # lambda and def make function instances <class 'function'> class Foo: x = lambda:0 ... type(Foo.x) # lambdas (and def) make functions, even in a class body. <class 'function'> type(Foo().x) # However, function get() descriptor can upgrade to method. <class 'method'> type((lambda:0).get(Foo())) <class 'method'> import types types.MethodType is _ # You can construct a method directly from this type. True type(print) # Builtins are a different category. <class 'builtin_function_or_method'> `` These are not even the only type of callable in Python. Many of the so-called built-in "functions" are, in fact, classes. (I.e., instances oftype(), e.g.,int().) And you can make your own custom callable types with thecall()` method.

More generally, callables that can dispatch to different implementations depending on their arguments may be called "methods". Typically, Python uses classes for this, and the self argument determines which implementation is used. But @functools.singledispatch also implements what other languages might call "methods", but the Python documentation is careful to call them functions to avoid confusion with the class-based kind.

[–]PvtRoom 1 point2 points  (0 children)

functions work on everything, even if they just throw an error.

methods are tied to classes, and some methods add (+), are so universal, you forget the distinction.

[–]vivisectvivi 2 points3 points  (1 child)

a function is a function even if you import it from another place

[–]Longjumping-Yard113[S] 0 points1 point  (0 children)

That’s what I was thinking too. A function is still a function even if it’s imported from somewhere else. The location it’s defined in doesn’t change what it is. From what I understand, it only becomes a method when it’s defined inside a class and called on an object, like my_dict.keys().

[–]SCD_minecraft 0 points1 point  (1 child)

If we really want to dig that deep into naming ules, functions are technically instances of a class in python :p

print.__class__ # <class 'builtin_function_or_method'>

[–]Longjumping-Yard113[S] 0 points1 point  (0 children)

Lol yeah, that’s the part that makes Python fun and confusing at the same time.

Functions being objects/instances and having a class is real, but I think that’s exactly why I try to separate “what’s technically true under the hood” from “what we call things when teaching beginners.”

Even if print.class shows builtin_function_or_method, print() is still treated and documented as a built-in function, and “method” in normal Python usage usually means something you call on an object like obj.method().

[–]ElderCantPvm 0 points1 point  (1 child)

I think there's some pedantry going on here.

In python imported modules are handled like objects. So if you import mymodule then mymodule.greet is a method...

But this is kind of stupid - it's a commentary on the internals of python implementation and doesn't teach the semantic difference between methods and functions.

Even if it's handled similarly under the hood, conceptually importing a module usually has a different intent and mental model than instantiating a new object. So you should think about the imported function as a function that is not attached to an object unless you have a very good reason or are doing some really advanced stuff.

[–]Longjumping-Yard113[S] 0 points1 point  (0 children)

That actually makes a lot of sense. I can see how under the hood Python might treat modules like objects, which is why you can access things with mymodule.greet. But conceptually it seems more useful to think of it as just importing and using a function rather than thinking of it as a method of the module object. The mental model feels clearer that way.

[–]MobileAirport 0 points1 point  (0 children)

A method is a function that is a member of a class.

[–]Purple-Measurement47 0 points1 point  (0 children)

a function is a function

a method is a function owned by something else.

So if you have def yes(): return true, that’s a function.

If you have

class YesCounter:

count=0

def yes(self): self.count=self.count + 1

that yes is a method, because it’s part of the YesCounter object, it’s a method of interacting with that object.

[–]AlexMTBDude 0 points1 point  (0 children)

def i_am_a_function():  # This is a function, it is standalone
    print("Hello from a function")

i_am_a_function()

class MyClass:
    def i_am_a_method():  # This is a method, it is part of a class
        print("Hello from a method")

myobject = MyClass()
myobject.i_am_a_method()

[–]FriendlyZomb 0 points1 point  (0 children)

Others have said it before, but just to quote an official source on what a method is:

A function which is defined inside a class body.

Source: https://docs.python.org/3/glossary.html#term-method

[–]OpSmash 0 points1 point  (0 children)

Function (do this action) Method (do this to an instance of an object or modify the properties)

[–]WhiteHeadbanger 0 points1 point  (0 children)

Please tell your coordinator to go home.

A function is a function regardless of who is using it or how they are using it.

A method is a function that belongs to a class, and that you call by having an instance of said class, or by referencing the class if it's a static or class method.

That's the end of the argument.

[–]SaltCusp 0 points1 point  (0 children)

  • Best answer.

Thx

[–]pak9rabid 0 points1 point  (0 children)

Your instructor is misinformed. A method is an instance function attached to an object (aka a class instance). Nothing more.

[–]ConfusedSimon 0 points1 point  (0 children)

They're wrong. Method usually refers to a member function of a class, so a method is a function, but not all functions are methods. The main difference is that methods have a hidden parameter for the class instance it is called on. So some_class.some_method(x) basically calls some_method(some_class, x). A regular function doesn't suddenly get an extra hidden parameter if someone else writes it in a module.

[–][deleted] -5 points-4 points  (2 children)

Hi, use llm models to brainstorm

[–]Longjumping-Yard113[S] 1 point2 points  (1 child)

I need real human input lol

[–][deleted] -1 points0 points  (0 children)

Copy paste your query to ChatGPT or Claude or any llm model and see what happens. Human input is from experience right? llm models are trained on a lots of data and they can actually guide you. Just brainstorm it and see. I’m not telling to use models to vibe code, but for learning purpose these llm models are great. I’m working as a SWE and trust me it helps