User Defined Functions

Simple Function

# This script demonstrates the definition and usage of a simple user-defined function in Python

# Example 1: Simple function
def greet():
    print("Hello, world!")

# Call the function
greet()

Function with Parameters

# This script demonstrates a user-defined function with parameters in Python

# Example 1: Function with parameters
def greet(name):
    print("Hello,", name)

# Call the function with an argument
greet("Alice")

Function with Return Value

# This script demonstrates a user-defined function with a return value in Python

# Example 1: Function with return value
def add_numbers(a, b):
    return a + b

# Call the function and store the result
result = add_numbers(5, 3)

# Print the result
print("Sum:", result)