Python version of JavaScript ES6 Symbols

Viewed 214

Is there a Python version of JavaScript's Symbol type? If not, what's the Pythonic way to declare a guaranteed-unique constant or property?

For example, in JavaScript, one could do:

const ALL_VALUES = Symbol()
const EVERY_OTHER_VALUE = Symbol()

function do_something_to_values(
    list_of_values, 
    values_to_affect
) {
    ...
}

And then one could call do_something_to_values(my_list, EVERY_OTHER_VALUE) and the function would check for equality to the EVERY_OTHER_VALUE constant.

How would one do this in Python?

1 Answers
Related