Python Functions vs Methods Explained Clearly

A clear beginner guide to Python functions vs methods. Learn the real difference, how each one is called, and the small mental model that makes the distinction permanent.

Pythonbeginner
7 min read

The Python functions vs methods question shows up the moment a beginner moves past the first few examples. Both look like named blocks of code that you call with parentheses, and both can take arguments and return values. The difference is not cosmetic. A function is a standalone callable. A method is a function that is permanently attached to a value of some type. The distinction shapes how you call it, how you read documentation, and how you decide which one to write yourself.

What a Python Function Really Is

A Python function is a named, callable object that exists independently of any value. You define it with the def keyword, give it a name, list its parameters in parentheses, and write its body indented underneath. You call it by writing its name followed by parentheses with the arguments inside. The function does not belong to anything. It lives in whatever scope it was defined in, usually a module or another function.

Built-in functions like len, range, and print follow this exact shape. You can pass them any value of any compatible type and the function decides what to do based on the argument. A function does not implicitly receive the object you are working on. Every value it operates on has to be passed in as a parameter, which is why function signatures often list two or three arguments even for small jobs. For a deeper picture of how functions sit in a Python program, our walkthrough on Python functions explained with real use cases covers definitions and call sites step by step.

What a Python Method Really Is

A Python method is a function defined inside a class, bound to instances of that class. You call it through the dot syntax, writing the value first, a dot, the method name, and then parentheses with any extra arguments. The receiver, which is the value on the left of the dot, is passed in automatically as the first argument of the method, named self by convention. That single piece of plumbing is the only mechanical difference between a method and a regular function.

Every built-in type ships with methods. A list has append, sort, and pop. A string has upper, split, and replace. A dictionary has keys, values, and items. These methods exist because each type knows how to operate on its own data. When you call words.split, you are saying that words is the input, and the split method already knows how to act on a string because it was defined as part of the str class. To see how the receiver model plays out for one of the most used types in the language, our piece on Python strings explained beyond just text walks through several string methods.

A Side by Side Look

The same task can usually be expressed as either a function call or a method call. The choice depends on which one reads more naturally and which one already exists in the language. The table below pins down the practical differences that you will care about as a beginner.

AspectFunctionMethod
Defined whereTop level of a module or inside another functionInside a class body
Call syntaxfunc(value)value.method()
ReceiverPassed explicitly as an argumentImplicit, becomes self
Belongs toA module namespaceA type or instance
Documentation lookuphelp(func)help(type(x).method)

A tiny code example makes the two call shapes concrete:

pythonpython
len("hello")
"hello".upper()

The first line calls a function and passes the string as its argument. The second line calls a method on the string itself, with the string acting as the implicit receiver. The table also explains why beginners sometimes mix the two up in error messages. An AttributeError happens when you try to call a method on a type that does not define it. A TypeError happens when you pass the wrong number of arguments to a function.

When to Write a Function or a Method

If the code you are writing operates on a single value of some type and the operation feels like part of that type's natural behaviour, a method is the right shape. If the code operates on several values, or coordinates between values of different types, or does not really belong to any single type, a function is the right shape. The third option, a static method or a module level function inside a class, is rare in beginner code and you do not need it yet.

A useful test is to read the call site you would write. If the most natural sentence is "ask the value to do something", write a method. If the most natural sentence is "do something with these values", write a function. Both shapes are first class in Python, and the language itself uses both extensively. To see how scope rules apply equally to both, our guide on Python global vs local variables explained visually covers the scoping that both functions and methods share.

Frequently Asked Questions

What is the difference between a function and a method in Python?

function is defined at the top level of a module or inside another function and is called by name with all of its arguments listed in the parentheses. A method is defined inside a class, called through the dot syntax on a value of that class, and automatically receives the value on the left of the dot as its first argument. The receiver mechanic is the only mechanical difference.

Why is the first parameter of a method called self?

By convention. Python passes the receiver of a method call as the first positional argument, and the community agreed long ago to name that parameter self in instance methods. Naming it anything else still works, but every Python reader expects self, so picking a different name makes the code harder to read for no benefit.

Can I turn a function into a method or the other way around?

Yes. A function can be assigned as an attribute of a class and used as a method, and a method extracted from a class can be called like a function if you pass the receiver explicitly as the first argument. Both manoeuvres are valid Python but rare in beginner code, and you should learn the natural shapes first. ### Key Takeaways - A function is a standalone callable, defined with def in a module or inside another function. - A method is a function defined inside a class, called through the dot syntax on an instance. - The receiver of a method call becomes the first argument, conventionally named self. - Use a method when the work feels like part of a single value's natural behaviour. - Use a function when the work coordinates between values or does not belong to any single type.

Conclusion

A function is a standalone callable that you pass arguments to. A method is a function attached to a type, called through the dot syntax, with the receiver becoming the first argument automatically. The line between the two is mechanical, not philosophical, and once you can see the implicit self argument in every method call, the distinction stops feeling slippery. The fastest way to lock in the model is to write the same small piece of logic twice, once as a function that takes the value as a parameter and once as a method on a small class. Calling both side by side and comparing the syntax makes the difference visible. After a single exercise like that, every future call site reads as one or the other without conscious thought.