I want to use a list that was created from a previous function in my other function.
After a bit of research it seems using return
is the way of doing it. However I cannot get it to work.
This is my code:
def FunctionA():
all_comments1 = [1,2,3,4]
return all_comments1
def FunctionB():
FunctionA()
all_comment_string1 = ''.join(all_comments1)
newlistings1 = all_comment_string1.split('\n')
print(newlistings1)
def DoSomething():
FunctionB()
DoSomething()
It gives me an error:
NameError: name 'all_comments1' is not defined
I want to know how I can define the variable successfully.