OneBite.Dev - Coding blog in a bite size

convert a string to an array in python

Code snippet on how to convert a string to an array in python

my_string = "Hello World!"
my_list = my_string.split()

This code begins by defining a string, “Hello World!” and assigning it to the variable, my_string. Next, the split() method is called on the string. This is a built-in method of python that splits up the string at each space and returns a list of strings. This list is then assigned to the variable my_list. This variable now contains an array of strings, with each index containing a word from the original string.

python