How to Convert String to List in Python

To convert a string to a list in Python, you can use the split() function.

The following example shows how to convert a string to a list in Python using the split() function.

Using split() Function

We can use the split() function to convert a string to a list.

Suppose we have the following string:

# Declare string
String1 = "11/12/2021, 15/04/2017, 28/01/2003, 1/9/2010, 12/5/2022, 19/02/2008"

# Convert string to list
List1 = String1.split(", ")

# Show list
print(List1)

Output: 👇️

['11/12/2021', '15/04/2017', '28/01/2003', '1/9/2010', '12/5/2022', '19/02/2008']

In this example, we use the split() function to convert the string String1 to a list List1. The output shows the list created from the string using the split() function.

Conclusion

We can use the split() function to convert a string to a list in Python. This method provides a convenient way to transform strings into lists.