How does split() work for arguments longer than a single character?


#1

Question

In the context of this exercise, how does split() work for arguments longer than a single character?

Answer

When we provide an argument that is a string of more than one character, then it will split on wherever that argument string occurs in the original string, very similar to when you provide just a single character argument.

The length of the argument string can be any length, but when you input an argument longer than the original string, it will not return anything.

string = "This123is123a123secret123message"
result = string.split("123")

print(result)
# ["This", "is", "a", "secret", "message"]