w3resource

Python: Get variable unique identification number or string

Python List: Exercise - 36 with Solution

Write a Python program to get a variable with an identification number or string.

Sample Solution:

Python Code:

# Define a variable 'x' and set its value to 100
x = 100

# Print the hexadecimal representation of the unique identifier (memory address) of 'x'
# 'id(x)' returns the memory address, and 'format(id(x), 'x')' formats it as a hexadecimal string
print(format(id(x), 'x'))

# Define a string 's' with the value 'w3resource'
s = 'w3resource'

# Print the hexadecimal representation of the unique identifier (memory address) of the string 's'
# 'id(s)' returns the memory address, and 'format(id(s), 'x')' formats it as a hexadecimal string
print(format(id(s), 'x'))

Sample Output:

7f71e94c4d50
7f71e9405df0 

Flowchart:

Flowchart: Get variable unique identification number or string

Python Code Editor:

Previous: Write a Python program to create a list by concatenating a given list which range goes from 1 to n.
Next: Write a Python program to find common items from two lists.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/list/python-data-type-list-exercise-36.php