Created
February 24, 2022 19:51
-
-
Save dtxe/90d41702c23c7f69010d3d5e57e0b9df to your computer and use it in GitHub Desktop.
This file contains 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 characters
def list_mutator(inner_list): | |
inner_list.append(4) | |
def list_setter(inner_list): | |
inner_list = inner_list + [4] | |
def list_returner(inner_list): | |
inner_list = inner_list + [4] | |
return inner_list | |
outer_list = [1, 2, 3] | |
print('') | |
print('list_mutator old:\t' + str(id(outer_list)) + ' | ' + repr(outer_list)) | |
list_mutator(outer_list) | |
print('list_mutator new:\t' + str(id(outer_list)) + ' | ' + repr(outer_list)) | |
outer_list = [1, 2, 3] | |
print('') | |
print('list_setter old:\t' + str(id(outer_list)) + ' | ' + repr(outer_list)) | |
list_setter(outer_list) | |
print('list_setter new:\t' + str(id(outer_list)) + ' | ' + repr(outer_list)) | |
outer_list = [1, 2, 3] | |
print('') | |
print('list_returner old:\t' + str(id(outer_list)) + ' | ' + repr(outer_list)) | |
new_outer_list = list_returner(outer_list) | |
print('list_returner return val:\t' + str(id(new_outer_list)) + ' | ' + repr(new_outer_list)) | |
# list_mutator old: 2786847806464 | [1, 2, 3] | |
# list_mutator new: 2786847806464 | [1, 2, 3, 4] | |
# list_setter old: 2786858164672 | [1, 2, 3] | |
# list_setter new: 2786858164672 | [1, 2, 3] | |
# list_returner old: 2786854748608 | [1, 2, 3] | |
# list_returner return val: 2786858165184 | [1, 2, 3, 4] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment