[Python] How can I convert a string into a list of characters in Python? [duplicate]

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I want to convert a string into a list containing the individual characters of that string in Python. How can I do that in a simple way?

    my_string = "hello"


    Expected result: ['h', 'e', 'l', 'l', 'o']

    my_string = "hello"



    I tried splitting the string using the split() method, but it didn't work for characters.

    split_string = my_string.split() # This splits by spaces, not by characters.
    print(split_string)

    Continue reading...

Compartilhe esta Página