split()
` function in Python to split a string into a list of substrings based on a separator :# define a string
string = "The quick brown fox jumps over the lazy dog"
# split the string into words
words = string.split()
# print the list of words
print(words)
# split the string based on a separator
string2 = "apple,banana,orange"
fruits = string2.split(",")
print(fruits)
['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
['apple', 'banana', 'orange']
split()
` function is called without any arguments, which splits the string into a list of words based on whitespace characters (spaces, tabs, and newlines).split()
` function is called with a comma `,
` as an argument, which splits the string into a list of substrings based on the comma separator.