Python Forum
How to determine how many variables are referring the same id in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to determine how many variables are referring the same id in python?
#4
Quote:Why do want to do this?.
It also break over integer 256.
>>> divyansh = 2222
>>> jhon = 2222
>>> id(divyansh)
2362812091760
>>> id(jhon)
2362812091920
>>> id(2222)
2362812088752
Then it step out small integer optimization between -5 and 256.

actually i am doing this because i want to pass two variables to max() function and what ever is greater i want to have the name printed of that variable and the value of that variable,

ex- divyansh is the name of the person and 22 is the age
jhon is the name of the person and 21 is the age
so i want to have the name and the age of the person printed
so i did-->
divyansh=22
jhon =21
determine_the_name=max(divyansh,jhon)
# but here determine_the_name will have 22 not the variable name divyansh 
# so i taught that id of 22 will be same and if any how i can know the references of that id then it will lead to the variable name somehow

i know i can do this very easily through if-else ladder but i don't want to go that way,

and as we know this concept of referring works in decorators so i thought there can be a similar way to approach this
# in decorators we can get the real wrapper function name by using __name__ method onto the decorated method as
print(decorated_function.__name__) # will return the name of the actual function which is responsible the functionality of decorated_function 
Reply


Messages In This Thread
RE: How to determine how many variables are referring the same id in python? - by divyansh - Aug-04-2020, 01:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Determine number of all the immediately adjacent points in python zackk 1 1,899 Feb-06-2021, 09:23 AM
Last Post: zackk
  How to determine pen color from an image? robie972003 2 2,431 Mar-24-2019, 10:06 PM
Last Post: robie972003
  determine if an number is in a list Dbeah 7 3,831 Nov-06-2018, 12:11 PM
Last Post: buran
  determine if an number is in a list Dbeah 1 2,273 Nov-04-2018, 04:50 PM
Last Post: stullis
  how to determine if an object is a number Skaperen 6 4,057 Jul-11-2018, 08:18 PM
Last Post: Skaperen
  How Do I Determine indentation in AST? jimo 3 4,304 Jul-01-2018, 04:25 PM
Last Post: buran
  Determine whether a method was overridden porton 6 6,187 Nov-14-2016, 09:51 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020