> For the complete documentation index, see [llms.txt](https://university-west.gitbook.io/programming-paradigms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university-west.gitbook.io/programming-paradigms/programming-fundamentals/functions.md).

# Functions

#### Functions/Methods in Computer Programming

In computer programming, functions or methods (the terms are often used interchangeably, though with some differences depending on the programming paradigm and language) are reusable blocks of code designed to perform a specific task. A function typically takes input (known as arguments or parameters), performs some operations on the input, and then returns an output. The main purpose of functions is to segment large programs into smaller, manageable, and reusable components. This enhances readability, makes maintenance easier, and helps avoid redundancy.

**Functions in Python**

A Python function is defined using the `def` keyword, followed by the function name and parentheses (`()`) which may include arguments. The code block within the function starts with a colon (`:`) and is indented.

**Example:**

```python
# Define a function in Python
def greet(name):
    return f"Hello, {name}!"

# Call the function
print(greet("Alice"))
```

Output:

```
Hello, Alice!
```

**Methods in C#**

In C#, a method is a code block containing a series of statements. Methods are defined within classes or structs, and they can perform operations and return values. Methods in C# are defined using the return type, the name of the method, and a pair of parentheses which can include parameters.

**Example:**

```csharp
using System;

class Program
{
    // Define a method in C#
    static string Greet(string name)
    {
        return $"Hello, {name}!";
    }

    static void Main(string[] args)
    {
        // Call the method
        Console.WriteLine(Greet("Bob"));
    }
}
```

Output:

```
Hello, Bob!
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://university-west.gitbook.io/programming-paradigms/programming-fundamentals/functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
