One way to split a string into an array of characters in Python is to use the list()
function. Here's an example:
main.py73 chars4 lines
Output:
main.py56 chars2 lines
In this example, we first define a string my_string
as "hello world". We then use the list()
function to convert the string to a list of characters and store it in the variable char_array
. Finally, we print char_array
to the console.
This will output the list of characters in the string, separated by commas.
gistlibby LogSnag