def fillList(listToFill,n): listToFill=range(1,n+1)
a new list is created inside the scope and disappears when the function ends. useless.
def fillList(listToFill,n): listToFill=range(1,n+1) return listToFill()
you will return the list and you should use it like this:
newList=fillList(oldList,1000)
- And finally, without returning arguments:
def fillList(listToFill,n): listToFill.extend(range(1,n+1))
and name it as follows:
fillList(oldList,1000)
Conclusion
Inside a function, if you want to change an argument, you can reassign it and return it, or you can call the methods of the object and not return anything. You cannot just reassign it as if you were outside the function and did not return anything, because it will not have an effect outside the function.
source share