1
import math as m

def f1():
    a = 10
    b = 20
    c = a+b
    print(c)
    print(m.sqrt(4))

    def num(a,b):
        d = a*b
        return d

How to call to num function in another pycharm module ?

1 Answer 1

1

You can't, the function num(a,b) is essentially a local variable inside f1(); it only exists when f1() is ran.

Just write num(a,b) not as a nested function and you can call it elsewhere (if you import it properly) and f1() still has access to it:

import math as m

def num(a,b):
    d = a*b
    return d

def f1():
    a = 10
    b = 20
    c = a+b
    d = num(a,b)
Sign up to request clarification or add additional context in comments.

3 Comments

I wants access nested function
You can access num() somewhere else now and your function still uses it. I think this does what you want?
Please attempt a proper stackoverflow search too. This was already answered here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.