To convert a string to an array in Python, you can use the string.split() method. It splits a string into a list, where each list element is each word that makes up the string.
Syntax
string.split(separator, maxsplit)
Parameters
- separator: It takes a separator as an optional parameter to split the String. By default, whitespace is a separator.
- maxsplit: It specifies how many splits to do. The default value is -1, which is “all occurrences“.
Return value
It returns a list of strings after breaking the given string by the specified separator.
Visual Representation

Example 1: Converting a string to an array
string = "I love Python"
arr = string.split()
print(arr)
Output
['I', 'love', 'Python']
Example 2: Use the split() method with a Separator

string = "I,love,Python"
arr = string.split(',')
print(arr)
Output
['I', 'love', 'Python']
Example 3: Converting a string to an array of characters
You can convert a string to an array of characters using the built-in list() function. When converting a string to an array of characters, whitespaces are also treated as characters.

string = "Python"
arr = list(string)
print(arr)
Output
['P', 'y', 't', 'h', 'o', 'n']
Related posts

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.
You can use list comprehensions to do str -> char[] as well
str = ‘abc’
result = [c for c in str]
result
type(result)
// [‘a’,’b’,’c’]
// list
how to convert a list
1.2175443743582222
1.2175624154470546
1.216812476226702
1.2135922330097086
1.2135922330097086
1.2174474363703431
to
[1.2175443743582222,
1.2175624154470546,
1.216812476226702,
1.2135922330097086,
1.2135922330097086,
1.2174474363703431]
array.split(‘\n’)
This is a great tutorial on how to convert a string to an array in Python.