fork download
  1. class Str:
  2. def __init__(self, s):
  3. self._str = list(s)
  4.  
  5. def __str__(self):
  6. return ''.join(self._str)
  7.  
  8. def __setitem__(self, idx, x):
  9. self._str[idx] = list(x) if isinstance(idx, slice) else x
  10.  
  11. def replace(self, what, with_):
  12. self._str = list(str(self).replace(what, with_))
  13.  
  14. A = Str('mystring')
  15. print(id(A), A)
  16.  
  17. A[0] = '-'
  18. print(id(A), A)
  19.  
  20. A[:] = 'newstring'
  21. print(id(A), A)
  22.  
  23. A.replace('new', 'replace')
  24. print(id(A), A)
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
4146919980 mystring
4146919980 -ystring
4146919980 newstring
4146919980 replacestring