Sometimes, we want to split a string by a delimiter in Python.
In this article, we’ll look at how to split a string by a delimiter in Python.
How to split a string by a delimiter in Python?
To split a string by a delimiter in Python, we can use the string’s split
method.
For instance, we write:
a = "MATCHES__STRING".split("__")
print(a)
We call split
on the string with the separator we want to split the string with as the argument.
Then we assign the returned list to a
.
Therefore, a
is ['MATCHES', 'STRING']
.
Conclusion
To split a string by a delimiter in Python, we can use the string’s split
method.