Q. The id() can be used to get the memory address of a variable Consider the following code and tell if the id () functions will return the same value or not (as the value to be printed via print()) ? Why?
[There are four print() function statements that are printing id of variable num below)num = 13
print(id(num))#1
num = num +3
print( id(num) )#2
num = num - 3
print( id(num))#3
num="Hello"
print(id(num))#4
Answer =
Output in pc may be different in your PC but the logic will same:-
1817291680432
1817291680528
1817291680432
1817332779056
>>>
1817291680528
1817291680432
1817332779056
>>>
Id does not depend on variables. It depends on the values of variables, so If the value is the same then Id will same.
For example:- In print statement #1 and #3 id is Same.
cant see the answer
ReplyDeleteOk, I have fixed it.
DeleteAnswer is not visible...
ReplyDeletePlease make it visible....
Ok, I have fixed it.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )