Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views2 pages

Function 5

The document explains the concept of functions in programming, highlighting their role in organizing code into reusable modules. It classifies user-defined functions into four types based on their parameters and return values: no parameters and no return, parameters but no return, no parameters but a return, and both parameters and return. Each type is illustrated with examples to demonstrate their usage.

Uploaded by

royrian149
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Function 5

The document explains the concept of functions in programming, highlighting their role in organizing code into reusable modules. It classifies user-defined functions into four types based on their parameters and return values: no parameters and no return, parameters but no return, no parameters but a return, and both parameters and return. Each type is illustrated with examples to demonstrate their usage.

Uploaded by

royrian149
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

A function is a block of code designed to perform a specific task.

Functions help organize code


into reusable modules, improving readability and maintainability. In programming, functions can
be classified into various types based on parameter passing and return type.

Classification of User-Defined Functions

User-defined functions can be categorized into four types based on whether they accept
parameters and return a value:

---

1. Functions with No Parameters and No Return Value

These functions do not take any input parameters and do not return a value.

Example: Used for simple tasks like printing a message.

def greet():
print("Hello, welcome to the program!")

# Calling the function


greet()

---

2. Functions with Parameters but No Return Value

These functions accept parameters (inputs) but do not return a value.

Example: Used when operations are performed using provided inputs.

def display_message(name):
print(f"Hello, {name}! Welcome!")

# Calling the function


display_message("John")

---
3. Functions with No Parameters but a Return Value

These functions do not take parameters but return a value to the caller.

Example: Used when a fixed computation or value is required.

def get_pi():
return 3.14159

# Calling the function


pi_value = get_pi()
print("Value of Pi:", pi_value)

---

4. Functions with Parameters and Return Value

These functions accept parameters and return a value after performing operations on the input.

Example: Used for tasks requiring both input and output.

def add_numbers(a, b):


return a + b

# Calling the function


result = add_numbers(5, 7)
print("Sum:", result)

---

You might also like