Junior
Is it possible to pass a function as an argument to another function?
sobes.tech AI
Answer from AI
Yes, it is possible. In Python, functions are "first-class" objects.
def greeting(name):
return f"Hello, {name}!"
def say_hello(func):
# Call the passed function
message = func("World")
print(message)
# Pass the greeting function as an argument
say_hello(greeting)