Alok Agarwal’s Post

🚀 Python Concept Simplified: Function vs Method One of the most common confusions beginners have in Python is the difference between a Function and a Method. Let’s end that confusion once and forever 👇 🔹 FUNCTION A function is an independent block of code. It is written outside a class and can be called directly using its name. ➡️ Think of it as a free worker — works independently. def add(a,b): return a+b add(5,7) # function call 🔹 METHOD A method is a function that belongs to a class. It must be called using an object. ➡️ Think of it as a worker inside a company (class) — works only through that company’s object. class Calculator: def add(self,a,b): return a+b c = Calculator() c.add(5,7) # method call 🧠 Shortcut to remember If called like this It is name() Function object.name() Method One Line Summary Every method is a function, but not every function is a method.

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories