4 ms·
> I thought Ruby ensured there was only one symbol with given contents, so that equality testing for symbols reduces to pointer equality. I don't Python strings
by BerislavLopac 10y ago
> I thought Ruby ensured there was only one symbol with given contents, so that equality testing for symbols reduces to pointer equality. I don't Python strings behave that way.
In Python, string literals are reused, if that is what you meant.
>>> a = 'abc'
>>> b = 'abc'
>>> a is b
True
- infinite8s 10y agoString literals up to a certain size are reused.
- omaranto 10y agoOh, cool, I didn't know that. I think in Ruby all symbols are reused, whether they are literals or constructed programatically. (Unlike Common Lisp symbols which can also de 'uninterned' if they are not literals.)
- gsnedders 10y agoThis isn't guaranteed by the language, even if CPython does it. What is guaranteed is intern('abc') is intern('abc').