What happens when we assign same values in two variables, is their address remains same?


Warning: Trying to access array offset on false in /home3/indiakep/public_html/wp-content/plugins/dw-question-answer/inc/Template.php on line 8
All QuestionsCategory: PythonWhat happens when we assign same values in two variables, is their address remains same?
chetan shidling asked 6 years ago

I need short information.

2 Answers
chetan shidling answered 6 years ago

Let’s see one example:

>>> a = 10
>>> b = a
>>> a

10

>>> b

10

>>> id(a)            //To get address

1864841616

>>> id(b)

1864841616
The address is same because the value of both variables are same, that’s why python is called memory efficient.

Krishan answered 6 years ago

Thank you so much