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 ?

Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39

1 Answers1

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)
Steven
  • 404
  • 1
  • 3
  • 10
  • I wants access nested function – gm_datascience Jun 10 '20 at 10:05
  • You can access `num()` somewhere else now and your function still uses it. I think this does what you want? – Steven Jun 10 '20 at 11:18
  • 1
    Please attempt a proper stackoverflow search too. This was already answered [here](https://stackoverflow.com/questions/17395338/how-to-access-a-function-inside-a-function). – Steven Jun 10 '20 at 11:28