They are wrong. But, it's a minor confusion they made and doing video courses which involves speaking and typing can be certainly challenging. No big deal.

When the function belongs to a class, it's a method (a more specialized form of a function). When it's outside of a class it's a function.

How do I know they are wrong?

You use this syntax to create one in Python:

class SomeClass:

   @classmethod
   def the_method(cls, vars):
       ....

   def instance_method(self, vars):
       ...

It's not a @classfunction decorator. It's a @classmethod decorator.

See the docs at https://docs.python.org/3/library/functions.html#classmethod

Answer from Michael Kennedy on Stack Overflow
🌐
DataScience+
datascienceplus.com › methods-vs-functions-in-python
Methods vs. Functions in Python | DataScience+
August 10, 2020 - But methods cannot be called by ... that is, the method is defined within a class and hence they are dependent on that class. A function is an organized block of statements or reusable code that is used to perform a single/related action. Python programming three types ...
People also ask

What is the main difference between a function and a method in Python?
The main difference between a function and a method in Python is their association with objects. Functions are standalone blocks of code that exist independently and can be called directly by their name. They are defined at the module level using the `def` keyword. Methods, on the other hand, are functions that belong to an object or class and must be called using dot notation on an instance of that class or on the class itself. Methods are defined within class definitions and have access to the attributes of the object through the `self` parameter, which is implicitly passed as the first argu
🌐
study.com
study.com › courses › computer science courses › general computer science lessons
Method vs. Function in Python | Overview, Differences & Examples ...
What are class methods and static methods, and when should I use them?
Class methods and static methods are special types of methods in Python classes that serve different purposes. Class methods, defined with the `@classmethod` decorator, operate on the class itself rather than on instances. They receive the class (`cls`) as their first parameter instead of an instance. Class methods are useful for creating alternative constructors or factory methods that return instances of the class or for methods that need to access or modify class variables. · Static methods, defined with the `@staticmethod` decorator, do not operate on either the class or its instances. The
🌐
study.com
study.com › courses › computer science courses › general computer science lessons
Method vs. Function in Python | Overview, Differences & Examples ...
Why would one use methods instead of functions?
Methods would be used instead of functions in Python when working with objects. Methods are functions defined within a class and are associated with an object, allowing them to operate on the attributes of an object and encapsulate behavior. This promotes object-oriented programming principles like encapsulation and code modularity. · Functions, on the other hand, are standalone code blocks that are not associated with any specific object. Functions help limit code repetition.
🌐
study.com
study.com › courses › computer science courses › general computer science lessons
Method vs. Function in Python | Overview, Differences & Examples ...
Top answer
1 of 8
228

Create a function. Functions do specific things, classes are specific things.

Classes often have methods, which are functions that are associated with a particular class, and do things associated with the thing that the class is - but if all you want is to do something, a function is all you need.

Essentially, a class is a way of grouping functions (as methods) and data (as properties) into a logical unit revolving around a certain kind of thing. If you don't need that grouping, there's no need to make a class.

2 of 8
43

Like what Amber says in her answer: create a function. In fact when you don't have to make classes if you have something like:

class Person(object):
    def __init__(self, arg1, arg2):
        self.arg1 = arg1
        self.arg2 = arg2

    def compute(self, other):
        """ Example of bad class design, don't care about the result """
        return self.arg1 + self.arg2 % other

Here you just have a function encapsulate in a class. This just make the code less readable and less efficient. In fact the function compute can be written just like this:

def compute(arg1, arg2, other):
     return arg1 + arg2 % other

You should use classes only if you have more than 1 function to it and if keep a internal state (with attributes) has sense. Otherwise, if you want to regroup functions, just create a module in a new .py file.

You might look this video (Youtube, about 30min), which explains my point. Jack Diederich shows why classes are evil in that case and why it's such a bad design, especially in things like API.
It's quite a long video but it's a must see.

🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-method-function-python
Difference between Method and Function in Python - GeeksforGeeks
July 11, 2025 - But Python has both concept of Method and Function. ... Method is called by its name, but it is associated to an object (dependent). A method definition always includes 'self' as its first parameter. A method is implicitly passed to the object on which it is invoked. It may or may not return any data. A method can operate on the data (instance variables) that is contained by the corresponding class...
🌐
Reddit
reddit.com › r/learnpython › when to use class methods vs. functions?
r/learnpython on Reddit: When to Use Class Methods vs. Functions?
January 12, 2021 -

I am new to python and object oriented programming in general, and so far, one thing I struggle with is when to define a method for a class vs a general function callable by any object (e.g. object.method() vs method(object)). It seems to me that the general rule is if different classes require a different algorithm to be called, then it makes sense to define it as a class method so that the switching will happen automatically by class and the code will be much cleaner. Is that the basic idea? Or is it more related to whether the default argument is going to be "self" anyway?

Also, in terms of when to define classes in general, it seems to me that if one variable name should hold many different fields (and those fields are desired to be able to be changed), then it is a good idea to make a class. Does that sound right?

Any other advice would be appreciated,

🌐
Reddit
reddit.com › r/learnpython › what is the difference between a class and a function? when to use each one?
r/learnpython on Reddit: What is the difference between a class and a function? When to use each one?
July 11, 2023 -

Hi! I have very less time working with python and now I am going through classes, but until now they look kind of similar to definition of functions. When should I use one and when another? Is there a clear example for it?

Thanks a lot!

Top answer
1 of 14
74
A function is a block of code that performs a specific task. It is defined using the def keyword in Python. For example, the following code defines a function called square that takes a number as input and returns the square of that number: def square(number): return number * number print(square(5)) A class is a blueprint for creating objects. It defines the properties and methods of an object. For example, the following code defines a class called Rectangle that has two properties, width and height, and one method, area. The area method calculates the area of the rectangle. class Rectangle: def __init__(self, width, height): self.width = width self.height = height def area(self): return self.width * self.height rectangle = Rectangle(10, 20) print(rectangle.area()) The main difference between a function and a class is that a function is a reusable block of code, while a class is a blueprint for creating objects. Functions are typically used to perform specific tasks, while classes are used to create objects that have properties and methods. So, when should you use a function and when should you use a class? Here are some general guidelines: Use a function when you need to perform a specific task that does not need to be associated with an object. Use a class when you need to create an object that has properties and methods. Here is a clear example of when to use a function and when to use a class: Let's say you want to write a function that calculates the factorial of a number. You would use a function because you do not need to create an object to store the factorial value. Let's say you want to write a program that manages a list of contacts. You would use a class because you need to create objects to represent each contact. The class would have properties to store the contact's name, email address, and phone number. The class would also have methods to add, remove, and update contacts. I hope this helps!
2 of 14
10
Classes are good at keeping state, and grouping together relevant functions that modify that state. If you have user data, name, address, phone number, date they joined, password, list of friends, etc. Having a function that adds a new friend to the list of friends would require lots of arguments to the function and complex data structures. add_new_friend(all_users_data, user_name, users_friends_list, friend_name) Or you can make a class that handles everything related to that user and can access all user related data, and would only need the "who to friend". user.add_friend(friend)
Find elsewhere
🌐
Python documentation
docs.python.org › 3 › tutorial › classes.html
9. Classes — Python 3.14.3 documentation
As in Modula-3, there are no shorthands for referencing the object’s members from its methods: the method function is declared with an explicit first argument representing the object, which is provided implicitly by the call. As in Smalltalk, classes themselves are objects.
🌐
Real Python
realpython.com › instance-class-and-static-methods-demystified
Python's Instance, Class, and Static Methods Demystified – Real Python
March 17, 2025 - Calling .class_method() shows that the method doesn’t have access to the DemoClass instance object that the instance method had access to. However, it can access the class, which you can see by the output <class 'demo.DemoClass'>. This output represents the class object itself. Remember that everything in Python is an object, even classes themselves! Notice how Python automatically passes the class as the first argument to the function when you call obj.class_method().
🌐
Study.com
study.com › courses › computer science courses › general computer science lessons
Method vs. Function in Python | Overview, Differences & Examples | Study.com
October 30, 2025 - Functions are standalone blocks of code that can be called directly by their name, while methods belong to objects or classes and are called using dot notation on an instance of a class.
Top answer
1 of 2
10

Yes. To be clear, methods are functions, they are simply attached to the class, and when that function is called from an instance it gets that instance passed implicitly as the first argument automagically*. It doesn't actually matter where that function is defined. Consider:

class FooBar:
    def __init__(self, n):
        self.n = n
    def foo(self):
        return '|'.join(self.n*['foo'])


fb = FooBar(2)

print(fb.foo())

def bar(self):
    return '*'.join(self.n*['bar'])

print(bar(fb))

FooBar.bar = bar

print(fb.bar())

*I highly recommend reading the descriptor HOWTO. Spoiler alert, Functions are descriptors. This is how Python magically passes instances to methods (that is, all function objects are descriptors who's __get__ method passes the instance as the first argument to the function itself when accessed by an instance on a class!. The HOWTO shows Python implementations of all of these things, including how you could implement property in pure Python!

2 of 2
5

Actually, methods and functions in Python are exactly the same thing!

It matters not one bit where it is defined. What matters is how it is looked up.

def defined_outside(*args):
    return args

class C:

    def defined_inside(*args):
        return args

C.defined_outside = defined_outside
defined_inside = C.defined_inside

instance = C()

print(         defined_inside (1,2))
print(         defined_outside(1,2))
print(instance.defined_inside (1,2))
print(instance.defined_outside(1,2))

which gives the output

(1, 2)
(1, 2)
(<__main__.C object at 0x7f0c80d417f0>, 1, 2)
(<__main__.C object at 0x7f0c80d417f0>, 1, 2)

(This will only work in Python 3: Two of these will produce a TypeError in Python 2.)

What is important to notice about the output is that, in the first two cases, the functions receive two arguments: 1 and 2. In the last two cases they receive three arguments: instance, 1 and 2.

In the cases where instance is passed to the function, the function is behaving like a method. In the cases where instance is not passed in, the function is behaving like a plain function. But notice that both behaviours are exhibited by both the function which was defined inside the classe and the one which was defined outside the class.

What matters is how the function was looked up. If it was looked up as an attribute of an instance of a class, then the function behaves like a method; otherwise it behaves like a free function.

[Incidentally, this binding behaviour only works for pure Python functions; it does not work for functions defined using the Python/C API. The latter always behave like functions and never like methods:

C.dir = dir
instance.dir()

will give you a directory of the global scope, not of instance, indicating that dir recived zero arguments, rather that receiving instance as an argument. ]

🌐
freeCodeCamp
forum.freecodecamp.org › python
Class vs Function - Python - The freeCodeCamp Forum
June 10, 2024 - How would I know when to use make a new class or rather just define a new function in programing. Both applications really still confusing
🌐
Medium
medium.com › code-applied › python-functions-vs-classes-fe5d48fdf587
Python Functions vs. Classes. Know when to use which one in this… | by Gustavo R Santos | Code Applied | Medium
May 31, 2025 - When you only need to perform a single action, functions are your best bet. For example, calculating the area of a circle or converting temperatures. Don’t overcomplicate things! Now, classes are like blueprints for creating objects. And we know that Python (like some other programming languages) is Object-Oriented, meaning that the object determines what you can or cannot do with it. Objects can have characteristics (attributes) or do something (methods).
🌐
TechVidvan
techvidvan.com › tutorials › python-methods-vs-functions
Python Methods vs Functions - What really differentiates them? - TechVidvan
August 22, 2024 - In a nutshell, both methods and functions perform tasks and may return some value. But the difference lies in the fact that methods are ‘associated’ with objects, while functions are not. That was all about Python Methods vs Functions.
Top answer
1 of 2
3

If your method calls a static method on the class, then it does require information on the class. You have a class method, not a static method. By declaring it @classmethod (and adding the cls parameter), you not only properly inform the reader, you allow polymorphism. An inheritor can reimplement the called static method and change behavior.

2 of 2
2

Python's static methods are intended for methods that are part of a class, and can be called as either a class method or an instance method: both Class.the_method() and self.the_method() would work. When the static method is called, it is not given an implicit first argument:

class Example:
  def instance_method_example(self, arguments):
    ...

  @classmethod
  def class_method_example(cls, arguments):
    ...

  @staticmethod
  def static_method_example(arguments):
    ...

If you merely want to create a helper function that is used within your class, do not use @staticmethod. Define a free function outside of the class. For example:

class Example:
  def some_method(self, argument):
    return _helper(argument, self.x)

def _helper(a, b):
  ...

The background of static methods in Python is the following: when you access an attribute of an object x.attribute or getattr(x, 'attribute'), then this name is looked up in the instance dict or the class dict. If an object is found in the class dict, it is checked whether that object is a “descriptor”: an object that describes how this attribute behaves, not an object that would be directly returned. Descriptors have dunder-methods like __get__, __set__, and __del__ that are invoked depending on whether the descriptor is accessed, assigned to, or deleted with the del operator.

Functions – the things you declare with def – are descriptors. By default, the __get__ descriptor binds the function to the instance argument (typically called self) and returns the bound function, so that it can be invoked as a method. But the various decorators change this behaviour:

  • a @classmethod def binds to the class object, not the instance
  • a @staticmethod def does not bind to any object and just returns the underlying function directly
  • a @property invokes the underlying function to retrieve a value

These differences are (partially) visible when looking at the repr() of the bound methods. With the first Example class:

  • instance_method_example
    • with class: Example.instance_method_example
      is <function Example.instance_method_example at 0x7f1dfdd6fd30>,
      the unbound function
    • with instance: <function Example.instance_method_example at 0x7f1dfdd6fd30>
      is <bound method Example.instance_method_example of <__main__.Example object at 0x7f1dfdddcb80>>,
      a method bound to the instance
  • class_method_example
    • with class: Example.class_method_example
      is <bound method Example.class_method_example of <class '__main__.Example'>>,
      a method bound to the class
    • with instance: Example().class_method_example
      is <bound method Example.class_method_example of <class '__main__.Example'>>,
      also a method bound to the class
  • static_method_example
    • with class: Example.static_method_example
      is <function Example.static_method_example at 0x7f1dfdd6fe50>,
      the unbound function
    • with instance: Example().static_method_example
      is <function Example.static_method_example at 0x7f1dfdd6fe50>,
      also the unbound function

As a table:

invoked on… no decorator @classmethod @staticmethod
… instance bound to instance bound to class unbound
… class unbound bound to class unbound
🌐
Quora
quora.com › Python-Function-versus-Class-what-is-the-difference-between-using-either-methods
Python Function versus Class: what is the difference between using either methods? - Quora
Answer (1 of 4): In classic object oriented programming, a class is supposed to bundle up some data along with specialty methods for manipulating that data. You might have a class representing an car which knows the position and direction of the car. You could uses the class’s functions (“instanc...
🌐
Quora
quora.com › Should-I-use-classes-or-functions-when-making-a-program-in-Python
Should I use classes or functions when making a program in Python? - Quora
Python (programming langu... ... Object-Oriented Programmi... ... I tend to use classes for objects that have a state. E.g. when you access a database you typically connect once, then run queries multiple times, and disconnect when done, all by calling appropriate methods. Doing so using a class that can hold and hide the database connection and all methods interfacing with the external database is much more convenient than using functions...
🌐
Dontusethiscode
dontusethiscode.com › blog › 2025-03-05_funcmethods.html
Python: functions vs methods
func is just a regular, standalone function. It takes any object and expects it to have a .value attribute. Inside the class T, we define a method func. This is an instance method, meaning it automatically receives self as its first argument when called on an instance. When we access t.func, Python gives us a bound method—this method is now “bound” to the specific instance t.
🌐
Codingem
codingem.com › home › python methods vs functions — what’s the difference?
Python Methods vs Functions — What's the Difference?
October 20, 2022 - The difference between a function and a method in Python is that a method is implemented inside a class. A function is implemented outside.
🌐
Python.org
discuss.python.org › python help
Rules to recognize a method? - Python Help - Discussions on Python.org
September 12, 2023 - I can read in the glossary, that the method is a function within or of the class. What are the rules for recognizing a method within a sample of the code?