W
W
Wex1652021-07-10 05:59:16
Python
Wex165, 2021-07-10 05:59:16

How to pass data from one function to another?

I can't figure out how to pass data from one function to another.

If I have the following structure:

-общая папка
        - папка с функциями
              -функция1.ру
              -функция2.ру
        -основной файл.ру


I will describe the main essence, I am preparing the functions that I will need later for the program to work. In the main file, I plan to call functions for performing calculations as needed. I can't figure out how to pass data from one function to another. For example, the file "function1.ru" contains the function:
def func ():
     a = input()

And so on, i.e. it only serves to collect data.
And in the file "function2.ru", for example, this data is processed:

def func2 ():
     c=a*2

I am importing these functions into the main file and cannot figure out how to connect them together so that one function receives data and then passes it to another.

Perhaps the indents will not be displayed. The main file.ru lies separately from the functions in the shared folder.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-07-10
@phaggi

To pass data from a function, use the return statement
. For example:

def func():
    return input('введи число:')

def func2(a):
    return a * 2

def func3(z):
    return int(z) * 2

print(func2(func()))
print(func3(func()))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question