Monday, October 6, 2025
HomeLanguagesPython Split String into Array or List of Characters

Python Split String into Array or List of Characters

Python program split or convert string into array or list of characters; In this tutorial, you will learn how to split string into given array and list of characters in Python.

How to split a string into an array or List of characters python

  • Python program to split the string into an array of characters using for loop
  • Python Split string by converting string to the list Using list() function
  • Python program to split string by space

Python program to split the string into an array of characters using for loop

  • Define a function, which is used to convert string into array using for loop.
    .medrectangle-4-multi-340{border:none!important;display:block!important;float:none!important;line-height:0;margin-bottom:15px!important;margin-left:auto!important;margin-right:auto!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:250px;padding:0;text-align:center!important;width:100%}

  • Take input string from user by using input() function.
  • Call function and print result.
# Split string using for loop

# function to split string
def split_str(s):
  return [ch for ch in s]

# take string from user
str1 = input("Please Enter String : ")

print("string: ", str1)
print("split string...")
print(split_str(str1))

After executing the program, the output will be:

Please Enter String :  developer world
string:  developer world
split string...
['d', 'e', 'v', 'e', 'l', 'o', 'p', 'e', 'r', ' ', 'w', 'o', 'r', 'l', 'd']

Python Split string by converting string to the list Using list() function

In this python program, you will learn how to use list() function to convert each character into the list and returns the list/array of the characters.

Python program to convert string into list using list() function

  • Define a function, which is used to convert string into array using list() function.
  • Take input string from user by using input() function.
  • Call function and print result.
# Split string using list function

# function to split string
def split_str(s):
  return list(s)

# take string from user
str1 = input("Please Enter String : ")

print("string: ", str1)
print("split string...")
print(split_str(str1))

After executing the program, the output will be:

Please Enter String :  my world
string:  my world
split string...
['m', 'y', ' ', 'w', 'o', 'r', 'l', 'd']

Python split string by space

Her, you will learn how to use split() function to convert string word into the list and returns the list/array of the characters.

Python program to split string by space

# Split string using split function

txt = "hello world, i am developer"

x = txt.split(" ")

print(x)

After executing the program, the output will be:

[‘hello’, ‘world,’, ‘i’, ‘am’, ‘developer’]

Recommended Python Tutorials

RELATED ARTICLES

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6781 POSTS0 COMMENTS