To output a list object name in Python, we can make use of the print statement and the id() function. The id() function returns the unique identifier of an object in Python.
Here's an example:
main.py131 chars4 lines
Output:
main.py40 chars2 lines
In the code above, we created a list my_list and then used a list comprehension to loop through all the objects in the global namespace and find the one with the same memory address as my_list. We then printed the name of the object using the print statement. This approach allows us to output the variable name of any object, not just lists.
gistlibby LogSnag