Created
December 16, 2024 22:44
Revisions
-
jonocarroll created this gist
Dec 16, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ >>> def make_a_list(val1 = 0, val2 = 0, lst = []): ... lst.append(val1) ... lst.append(val2) ... return lst >>> # you need to know that you're modifying base_list >>> base_list = [1, 2, 3, 4] >>> extend_list = make_a_list(5, 6, base_list) >>> print(extend_list) [1, 2, 3, 4, 5, 6] >>> # so it's now the same as extend_list >>> print(base_list) [1, 2, 3, 4, 5, 6] >>> # good luck if you don't know it's referenced >>> # in this case lst = [] is defined at >>> # function definition and is mutable >>> my_list = make_a_list(3, 4) >>> print(my_list) [3, 4] >>> other_list = make_a_list(7, 8) >>> print [3, 4, 7, 8]