Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a function defined in another function

Can I call a function nested inside another function from the global scope in python3.2?

def func1():
    def func2():
        print("Hello")
        return
    return

Is ther a way to call func2() from outside func1()?

like image 506
charmoniumQ Avatar asked Dec 10 '11 15:12

charmoniumQ


People also ask

Can you call functions in other functions?

It is important to understand that each of the functions we write can be used and called from other functions we write. This is one of the most important ways that computer scientists take a large problem and break it down into a group of smaller problems.

How do you call a function from another function in C?

Syntax to Call a Function We can call a C function just by passing the required parameters along with function name. If function returns a value, then we can store returned value in a variable of same data type. int sum = getSum(5, 7); Above statement will call a function named getSum and pass 5 and 7 as a parameter.

How do you call one function inside another function in Python?

In Python, it is possible to pass a function as a argument to another function. Write a function useFunction(func, num) that takes in a function and a number as arguments. The useFunction should produce the output shown in the examples given below.

Can I call a function inside another function Javascript?

Approach: Write one function inside another function. Make a call to the inner function in the return statement of the outer function. Call it fun(a)(b) where a is parameter to outer and b is to the inner function.


1 Answers

No, unless you return the function:

def func1():
    def func2():
        print("Hello")
    return func2

innerfunc = func1()
innerfunc()

or even

func1()()
like image 92
Fred Foo Avatar answered Oct 06 '22 00:10

Fred Foo