Search code examples
pythonfunctionmodular

How can a function use variables generated by other (functions) as parameters for itself in python?


I'm learning python and I would like to separate the different processes of my code into different functions. To do that I need to give variables of previous function as a parameter to an other function . I tried some thing like this

def F1 (A):
   B=A+1 

def F2 (B):
   C=B+1
   print C  

F1(1) F2()

For example in this case I expect to get 3 as a final result.

But It doesn't work.


Solution

  • Just return it:

    def F1 (A):
       return A+1
    
    def F2 (B):
       C=B+1
       print C
    
    # Then use it as parameter
    F2(F1(1))