-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmutable-immutable.py
More file actions
27 lines (26 loc) · 857 Bytes
/
Copy pathmutable-immutable.py
File metadata and controls
27 lines (26 loc) · 857 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
'''
If you send a mutable object to a function and change it there — it will be changed after exiting the function,
unlike an immutable object:
'''
def fruts(param_list: list, param_string: str, param_word: str):
param_list.append(param_word)
param_string += param_word
print(f'''Inside func:
List: {param_list},
ID list: {id(param_list)}
String: {param_string}
ID string: {id(param_string)}''')
arg_list = ["apple", "banana"]
arg_string = "I love fruts"
arg_word = "orange"
print(f'''Before func:
List: {arg_list}
ID list: {id(arg_list)}
String: {arg_string}
ID string: {id(arg_string)}''')
fruts(arg_list, arg_string, arg_word)
print(f'''After func:
List: {arg_list}
ID list: {id(arg_list)}
String: {arg_string}
ID string: {id(arg_string)}''')