0

How can I use a variable that we defined inside the function inside another function?

For Exemple:

def fx(): 
    x = 5
    return x + 5


def fy():
    return x + 10


fx()
fy()


"""
the output i wanted : 15
"""
Selman
  • 274
  • 2
  • 4
  • 17
  • 2
    You can make `x` global, but it might make more sense if `fx()` just returned 5. Then you can store the output of `fx()` and pass it to `fy()`, where `fy` takes an argument. Generally speaking, you want to avoid globals as much as possible. – Kraigolas Jan 25 '22 at 15:02

1 Answers1

0

The solution @Kraigolas mentioned implemented

def fx(): 
    x = 5
    return x



def fy(x):
    print(x)


fy(fx())