Is it possible to add your own custom function to an already existing object?
For example, the 'string' datatype has no built-in reverse()
function unlike in a list
, is there a way to add a reverse function such that if I have a string variable var
, var.reverse()
returns the string in reverse?
One way I think this would work is if I create a class CustomString
that has the same properties as a string but with an additional defined reverse function, is this possible? (I'm not yet familiar with Python OOP)
Or is there another way of doing this?