Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c1a4bd

Browse files
authored
Create Pass_by_reference3.py
1 parent 1acf2b2 commit 8c1a4bd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎docs/OOPS/Pass_by_reference3.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
In python, everything is an object.
3+
Hence when we pass a list to a function and when we modify the list,
4+
the changes are reflected outside the function as well.
5+
For example, we can see that there is only one object and value and data are references to that object.
6+
'''
7+
8+
def change_function(data):
9+
print ("Id of list received in method", id(data))
10+
data[1] = 500
11+
print ("Id of list after element modification in method", id(data))
12+
13+
value = [100, 200, 300]
14+
print ("List and its id before method call", value, id(value))
15+
change_function(value)
16+
print ("List and its id after method call ", value, id(value))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /