Python string Method - split()

https:/‮figi.www/‬tidea.com

The split() method is a built-in string method in Python that splits a string into a list of substrings based on a specified separator.

The syntax for using split() method is as follows:

string.split(separator, maxsplit)

Here, string is the original string, separator is the substring to use as the separator (optional), and maxsplit is the maximum number of splits to perform (optional). If separator is not specified, the method uses any whitespace character as the separator. If maxsplit is not specified, the method performs as many splits as possible.

The method returns a list containing the resulting substrings.

Here's an example of using the split() method:

string = "Hello, World!"
substrings = string.split(",")
print(substrings)

Output:

['Hello', ' World!']

In the example above, the split() method was used to split the original string "Hello, World!" based on the comma separator (","). The resulting list is stored in the variable substrings, which contains the two substrings: "Hello" and " World!".