How to pass a runnable procedure (a function) as a parameter and run it in Python

2 Answers

0 votes
from typing import Callable

# Control function that takes another function and executes it
control: Callable[[Callable[[], None]], None] = lambda f: f()

def say():
    print("abcd")

# Calling the control function with 'say'
control(say)



'''
run:

abcd

'''

 



answered May 21, 2025 by avibootz
0 votes
# Control function that takes another function and executes it
def control(f):
    f()

def say():
    print("abcd")

# Calling the control function with 'say'    
control(say)



'''
run:

abcd

'''

 



answered May 21, 2025 by avibootz
...