The Power of Subscripts in Swift
swiftbysundell.com
swiftbysundell.com
https://docs.python.org/3/reference/datamodel.html#object.__...
I admit I don’t have a ton of experience in other languages. Is this an uncommon language feature?
I know c++ allows you to overload both the method operator and subscript operators.
At the end of the day it’s just a form of operator overloading, and is generally present in languages that value expressiveness. Python and C++ (as mentioned), as well as Ruby, Rust, Kotlin from the top of my head. There are many more.
By the way, slightly off-topic—Swift does have a fairly unique feature regarding operators: you can create entirely new ones, not just overloading those existing for some other types.
All Lisp and ML derived languages, for example.