Addressing part of a string via the array syntax in Python
python, string
Solution
As Adam pointed out, reading from a string array is possible in Python using the indexing syntax. What isn't possible though is writing to a string using this syntax:
>>> s = 'bar'
>>> s[2] = 'z'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
Maybe this was the problem you ran into?
Problem
Is it, in Python, possible to address a specific character in a string by the standard array syntax? Example, PHP: ``` $foo = 'bar'; echo $foo[1]; // Output: a ``` It didn't work like in PHP so I wanted to know if it is possible using some other way?