23
loading...
This website collects cookies to deliver better user experience
list()
. We will look at this method below. However, in this method, Python would not know where each item starts and ends, returning a list of characters. Hence, Python provides a few alternate methods which can be used to convert a string to a list.string.split( delimiter, maxsplit)
str_1 = "Hire the top 1% freelance developers"
list_1 = str_1.split()
print(list_1)
#Output:
#['Hire', 'the', 'top', '1%', 'freelance', 'developers']
str_1 = "Hire-the-top-1%-freelance-developers"
list_1 = str_1.split("-")
print(list_1)
#Output:
#['Hire', 'the', 'top', '1%', 'freelance', 'developers']
str_1 = "Hire freelance developers"
list_1 = list(str_1.strip(" "))
print(list_1)
#Output:
['H', 'i', 'r', 'e', ' ', 'f', 'r', 'e', 'e', 'l', 'a', 'n', 'c', 'e', ' ', 'd', 'e', 'v', 'e', 'l', 'o', 'p', 'e', 'r', 's']