Search code examples
pythonfunctionparametersreturnarguments

Trying to wrap my head around python functions


I'm trying to print:

gibberish1
2

by using multiple functions.

I'm not sure in what way the functions should be called, what arguments said call(s) would require or the parameters I need for the functions in the scenario below.

__

How do I go about utilizing both functions in the following case?

def function_one():
    variable_one = 1
    variable_two = 2
    return variable_one, variable_two


def function_two():
    use_function_one_variable = 'gibberish' + str(variable_one)
    print(use_function_one_variable)
    print(variable_two)

Solution

  • The following code snippet:

    def function_one():
        variable_one = 1
        variable_two = 2
        return variable_one, variable_two
    
    
    def function_two():
        variable_one, variable_two = function_one()
        use_function_one_variable = 'gibberish' + str(variable_one)
        print(use_function_one_variable)
        print(variable_two)
    
    function_two()
    

    produces your desired output:

    gibberish1
    2