Why are Python strings immutable? Best practices for using them

前端 未结 6 1626
后悔当初
后悔当初 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:47

    Immutable strings makes programming much easier, which is why C# and Java use them too.

    Had strings been mutable, you would not be able to trust any externally-provided string, since a malicious caller could change it underneath you.
    It would also make multi-threading much more difficult.

提交回复
热议问题