TypeError: 'str' object does not support item assignment - 12 Causes and Fixes
TypeError: 'str' object does not support item assignment means you tried to write into a Python string: s[0] = "H" , s[0:4] = "...." , or data["key"] = value where data turned out to be text instead of a dict. Strings are immutable , so Python never exposes a way to store into one - str simply has no __setitem__ . That single message covers two very different bugs. Either you genuinely want to edit characters and have to rebuild the string instead of patching it, or - far more often in real code - the name you indexed is a str when you expected a dict , list , or parsed JSON object. Below are 12 causes ordered by how often they show up in production code, each with a reproduction, the corrected lines, and a way to confirm the fix. If your case matches none of them, work the diagnostic checklist - it separates the "edit text" bug from the "wrong type" bug in two steps. Error TypeError: 'str' object does not s...