-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbad_args_code.py
More file actions
34 lines (24 loc) · 854 Bytes
/
bad_args_code.py
File metadata and controls
34 lines (24 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# mutable default
def add_to_list(value, list_to_add_to: list = []):
list_to_add_to.append(value)
return list_to_add_to
# immutable default
def add_to_number(value, number_to_add_to: int = 0):
number_to_add_to += value
return number_to_add_to
# immutable default
def add_to_list_v2(value, list_to_add_to: list | None = None):
if list_to_add_to is None:
list_to_add_to = []
list_to_add_to.append(value)
return list_to_add_to
if __name__ == "__main__":
print(F"{add_to_list(value=1)=}")
print(F"{add_to_list(value=1)=}")
print(F"{add_to_list(value=1)=}")
print(F"{add_to_number(value=2)=}")
print(F"{add_to_number(value=2)=}")
print(F"{add_to_number(value=2)=}")
print(F"{add_to_list_v2(value=3)=}")
print(F"{add_to_list_v2(value=3)=}")
print(F"{add_to_list_v2(value=3)=}")