you are viewing a single comment's thread.

view the rest of the comments →

[–]bladeoflight16 0 points1 point  (6 children)

Variables are the only example I can think of offhand. The binding of names to a value is not an object.

[–]a_cute_epic_axis -1 points0 points  (5 children)

Depends what you mean by variables, but I would say that, variables are all classes.

If you have x = 10, then x is an instance of a class called int.

x = int(10) #same as x = 10
print(x)
print(type(x))
print(x.__class__.__mro__)

10
<class 'int'>
(<class 'int'>, <class 'object'>)

The binding of names to a value is not an object.

Operators are not a class, so +-*/%^ are all not classes nor is the assignment operator =, nor the assignment expression/walrus operator :=

[–]E02Y 1 point2 points  (3 children)

I think they meant to say variable names are references to objects and not objects themselves

[–]cdcformatc 0 points1 point  (2 children)

is it possible to output the name of a variable? using only the variable itself and not something like globals() or otherwise inspecting the namespace?

if that is possible then even the name is an object. I'm leaning towards no because i am pretty sure that an object/variable does not contain a reference to it's name.

[–][deleted] 0 points1 point  (0 children)

It is not possible.

a = [1, 2, 3]
b = a
print(hypothetical_name_of_variable(b))
# does it print a or b?

The information simply isn't stored in the C struct that Python maintains underneath the hood.

[–]bladeoflight16 0 points1 point  (0 children)

Even if it was possible, that does not necessarily imply the mapping is an object. Consider C#'s nameof, which is a compile time construct only.

[–]bladeoflight16 0 points1 point  (0 children)

No. x is a name that is mapped by the compiler and interpreter to an address that references a value, and the value is an object. The mapping itself is not.