This is a bit of a hard question to answer without an example, but I will try my best. So let's say you want to call a function create_list
and have it make your list. You could do it a few ways. This first example is how you could create the list inside of the create_list
.
def create_list(arg1, arg2, arg3):
result = []
result.append(arg1)
result.append(arg2)
result.append(arg3)
# Or whatever the code is to generate the list
return result
my_list = create_list("Hello", "world", "!")
print(my_list)
Alternatively, you could create a list in your main function and have create_list
modify it.
def create_list(list_arg, arg1, arg2, arg3):
list_arg.append(arg1)
list_arg.append(arg2)
list_arg.append(arg3)
# Or whatever the code is to generate the list
my_list = []
create_list(my_list, "Hello", "world", "!")
print(my_list)
There are many other ways to do this depending on what you are looking for exactly but those are the most basic and will work in a majority of cases.