Write a Python program to get variable unique identification number or string


This program demonstrates how to obtain the memory address of an object in Python. The program uses the built-in function id() to obtain the memory address of an object and the format() function to convert the returned address to a hexadecimal representation.

The variable x is assigned the value 30, and the id() function is used to obtain the memory address of this variable. The returned address is then passed as an argument to the format() function, which converts the address to a hexadecimal representation using the format specifier 'x'. This hexadecimal representation of the memory address is then printed.

Similarly, the variable s is assigned the string "Tutor Joes", and the id() function is used to obtain the memory address of this variable. The returned address is then passed as an argument to the format() function, which converts the address to a hexadecimal representation using the format specifier 'x'. This hexadecimal representation of the memory address is then printed.

Source Code

x = 30
print(format(id(x), 'x'))
s = "Tutor Joes"
print(format(id(s), 'x')) 
 

Output

7005f980
c24bb0

Example Programs