Last active
January 21, 2020 14:37
-
-
Save scandiumby/de139e7e231b4dbb6f888c79442205f6 to your computer and use it in GitHub Desktop.
Mutable and immutable args for functions in Python3
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 characters
class AutoInc: | |
current_index = 0 | |
def __call__(self): | |
self.current_index += 1 | |
return self.current_index | |
def append_to_list(alist: list): | |
alist.append(7) | |
def del_var(v): | |
del v | |
def set_var(v): | |
v = 5 | |
def append_by_yeild(alist: list): | |
alist.append(8) | |
yield | |
alist.append(9) | |
if __name__ == '__main__': | |
list_ = [1, 2] | |
int_ = 10 | |
list2_ = list_ | |
append_to_list(list_) | |
del_var(int_) | |
del_var(list_) | |
set_var(int_) | |
i = AutoInc() | |
print(f'{i()}: {list_=}') | |
print(f'{i()}: {int_=}') | |
print(f'{i()}: {list2_=}') | |
saved_func = append_by_yeild(list2_) | |
print(f'{i()}: {list_=}') | |
del list_ | |
next(saved_func) | |
print(f'{i()}: {list2_=}') | |
print(f'{i()}: {list_=}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment