Function

Function

A function is a named, reusable block of code that performs a specific task. Instead of writing the same instructions over and over, you give them a name and call that name whenever you need them.

Built-in functions#

Programming languages come with a set of built-in functions that are ready to use. They cover common tasks like displaying text, reading input, or performing calculations. You don’t need to know how they work inside — just how to call them.

Method

A method is a function that belongs to a class. It defines what an object can do.

Where a plain function stands on its own, a method is always attached to a class. When you call a method, you call it on a specific object — and the method can work with that object’s data.

Defining a Method#

A method is defined inside the class body. It has a name, a return type, and a body.