In Python, functions are first-class objects, which means they can be passed as arguments to other functions.
Example Code:
# Function to apply another function to a list of numbers
def apply_function_to_list(numbers, func):
result = []
for num in numbers:
result.append(func(num))
return result
def square_number(number):
return number ** 2
data = [1, 2, 3, 4, 5]
squared_data = apply_function_to_list(data, square_number)
print(squared_data) # Output: [1, 4, 9, 16, 25]