Why are Python strings immutable? Best practices for using them

前端 未结 6 1625
后悔当初
后悔当初 2020-12-02 12:43
  1. What are the design reasons of making Python strings immutable? How does it make programming easier?
  2. I\'m used to mutable strings, like the ones in C. How am
6条回答
  •  余生分开走
    2020-12-02 13:35

    Immutable strings can be keys in dictionaries and similar data structures, without the need to copy the strings. It is easier to make a mutable wrapper around an immutable string than the other way around.

提交回复
热议问题