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?
The keyword you’re looking for is sentinel. There’s been lots of discussion of this over the years. This is a good fairly recent solution
https://www.revsys.com/tidbits/sentinel-values-python/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With