Do I have to return a list if I append to it inside a function?

Viewed 55

Consider a function in Python that gets as one of its arguments a list and inside it we append something to it. For instance:

def add_new_number_squared(new_number, numbers_list):
    numbers_list.append(num**2)

my_list = [0]
add_new_number_squared(2, my_list)

Now my_list[1] will contain the value 4, but is it a good practice or should I return numbers_list inside add_new_number_squared instead? To be more clear, should I write:

def add_new_number_squared(new_number, numbers_list):
    numbers_list.append(new_number**2)
    return numbers_list

my_list = [0]
my_list = add_new_number_squared(2, my_list)

instead of the code above?

0 Answers
Related