You cannot do this. Well, at least not directly. Python does not allow adding custom methods / attributes to built-in types. This is simply the law of language.
() str:
class MyStr(str):
def change(self):
result=""
for index,item in enumerate(self):
if(index%2 !=0): result=result+item
return(result)
:
>>> class MyStr(str):
... def change(self):
... result=""
... for index,item in enumerate(self):
... if(index%2 !=0): result=result+item
... return(result)
...
>>> x = MyStr("hallo world")
>>> x
'hallo world'
>>> x.change()
'al ol'
>>> 'change' in dir(x)
True
>>>
MyStr str . , , str:
>>> x = MyStr("hallo world")
>>> x.upper()
'HALLO WORLD'
>>> x.split()
['hallo', 'world']
>>>
, MyStr change.