'How to pass object across functions? [closed]

learning and incorporating functions into a web-scraping project in python and ran into this problem. Basically I want to pass an object (pandas dataframe) to another function / across functions. Basically I want to pass y to out across functions: out.append(y).

def do_inner_thing(y):
    y = y + 1
    out.append(y)
    
def do_outer_thing():
    out = []
    x = 2
    do_inner_thing(x)
    print(out)

do_outer_thing()

#Desired Output: 3


Solution 1:[1]

I'm not too sure if this is what you meant or not but you're able to place 'out' outside of the function and make do_inner_thing(y) print the string of out.

out = []
def do_inner_thing(y):
    y = y + 1
    out.append(y)
    
def do_outer_thing():
    x = 2
    do_inner_thing(x)
    print(str(out)[1])

do_outer_thing()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Victor_G