Python String to Char Array (List)

February 24, 2019
text = "abc"
chars = list(text)

Loop each char in string

for c in text:
    print(c) # a, b, c

for c in chars:
    print(c) # a, b, c
for i in range(len(text)):
    print(text[i]) # a, b, c
    text[i] = 'x' # cannot perform character assignment to string

for i in range(len(chars)):
    print(char[i]) # a, b, c
    char[i] = 'x' # ok
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.