Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can pass an argument to a function without executing it immediately by using a closure or lambda function. Here's an example in Python:

def my_function(x):
    def inner_function():
        print(x)
    return inner_function

y = my_function("Hello")
# y is now a function that can be called later with no argument
y()  # prints "Hello"

In this example, my_function returns another function inner_function that remembers the value of the x argument. We assign the result of my_function("Hello") to y, which is now a function that we can call later without providing any arguments. When we call y() later, it prints "Hello".