Hacker News new | past | comments | ask | show | jobs | submit login

only thing about Lua is that strings are immutable so certain kinds of operations can be very slow.



They are also immutable in Python.



  >>> a = "string"
  >>> a[1] = 'g'
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: 'str' object does not support item assignment
  >>> b = a.replace('t', 'g')
  >>> b
  'sgring'
  >>> a
  'string'
  >>> id(b)
  3065252256L
  >>> id(a)
  3075481632L
Also from here[1]:

  Strings and tuples are immutable sequence types: such
  objects cannot be modified once created.
[1] http://docs.python.org/2/library/stdtypes.html#mutable-seque...


Oh. I guess I never thought of strings as immutable because there are so many ways to change them.


Given that they're immutable, you cannot change them. Instead all the operations returns a new, modified, string.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: