Convert String to List in Python

  • Post category:String

Python has a function called list() that converts a string to list. The list() function accepts a string as an argument and returns a list of its characters.

Let’s code it.

Step 1: Create a string

str = "CodeAllow"
print("str = ", str)
print("str type = ", type(str))

Step 2: Convert string to list

lst = list(str)
print("list = ", lst)
print("list type = ", type(lst))


str =  CodeAllow
str type =  <class 'str'>
list =  ['C', 'o', 'd', 'e', 'A', 'l', 'l', 'o', 'w']
list type =  <class 'list'>

Free resources to learn advanced skills: AiHints and CodeAllow