Python string splitting and concatenation methods
Python String Split and Join Methods
Python has the following methods to perform splitting and joining operations –
Number | Method and Description |
---|---|
1 | lstrip() Removes all leading spaces from a string. |
2 | rstrip() Removes all trailing spaces from a string. |
3 | strip() Performs both lstrip() and rstrip() operations on a string. |
4 | rsplit() Splits a string at the end and returns a list of substrings. |
5 | split() Splits a string based on the delimiter (or whitespace if not provided) and returns a list of substrings. |
6 | splitlines() Splits a string at line breaks and returns a list of each line without line breaks. |
7 | partition() Splits a string into three substrings at the first delimiter. |
8 | rpartition() Splits a string into three tuples of substrings at the last delimiter position. |
9 | join() Concatenates the string representations of the elements in a sequence into a single string, using a delimiter string. |
10 | removeprefix() Removes the prefix string and returns a new string. |
11 | removesuffix() Removes the suffix string and returns a new string. |
For more Python tutorials, please read: Top Python Tutorials