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 1acf2b2

Browse files
authored
Create Pass_by_reference2.py
1 parent d3a6484 commit 1acf2b2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎docs/OOPS/Pass_by_reference2.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''
2+
When we pass an object to a parameter, the parameter name becomes a reference variable.
3+
4+
Recollecting the balloon example, it is like creating one more ribbon to the same balloon.
5+
Thus there is one object with two reference variable, one the formal parameter and the actual parameter.
6+
Thus any change made through one reference variable will affect the other as well.
7+
'''
8+
9+
class Mobile:
10+
def __init__(self, price, brand):
11+
self.price = price
12+
self.brand = brand
13+
14+
def change_price(mobile_obj):
15+
print ("Id of object inside function", id(mobile_obj))
16+
mobile_obj.price=3000
17+
18+
mob1=Mobile(1000, "Apple")
19+
print ("Id of object in driver code", id(mob1))
20+
21+
mob1.change_price()
22+
print ("Price of mob1 ", mob1.price)

0 commit comments

Comments
(0)

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