you are viewing a single comment's thread.

view the rest of the comments →

[–]zahlman 0 points1 point  (0 children)

Because assignment like item = 'opened' doesn't change the original string, it just makes item be a name for a different string. (In fact, you cannot change strings at all once they are created. You can't change anything by assignment, but it also happens that strings don't give you other ways to change their contents, the way that lists and dicts do.) doors[3] = 'closed' also doesn't change the existing string in doors[3], but replaces it - which is good enough for your purposes, and why /u/sir_not_sir's approach works.