forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassByValandRef.py
More file actions
28 lines (21 loc) · 776 Bytes
/
PassByValandRef.py
File metadata and controls
28 lines (21 loc) · 776 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
# python neither uses pass by value nor pass by refrence
def manipulate(a):
print("id before manipulating : ", id(a))
a = 10 # it is immutable so after assigning a value id will change
print("a : ", a)
print("id after manipulating : ", id(a))
a = 4
print("id before calling : ", id(a))
manipulate(a)
print("a :", a)
print("id after calling : ", id(a))
def update_lst(lst):
print("id before manipulating : ", id(lst))
lst[2] = 10 # it is mutable so after updating a list we re geeting updated list but with same id because list is mutable
print("lst : ", lst)
print("id after manipulating : ", id(lst))
lst = [4, 104, 410]
print("id before calling : ", id(lst))
update_lst(lst)
print("lst :", lst)
print("id after calling : ", id(lst))