my_str = "This is a string"
print(my_str.split())
comma_str = "Apple, Banana, Orange"
print(comma_str.split(", "))
Output
["This", "is", "a", "string"]
["Apple", "Banana", "Orange"]
In the above code examples, the first example splits a string into a list of substrings based on whitespace. The second example does the same but uses a comma and space as the delimiter.
0 Comments