- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to split string by a delimiter str in Python?
Python's String class has a method called split() which takes a delimiter as optional argument. Default delimiter for it is whitespace. You can use it in the following way:
>>> 'aa-ab-ca'.split('-') ['aa', 'ab', 'ca'] >>> 'abc mno rst'.split(' ') ['abc', 'mno', 'rst']
You can also use regex for this operation. The re.split method takes a delimiter regex and the string and returns the list. For example:
>>> import re >>> re.split('-', 'aa-ab-ca') ['aa', 'ab', 'ca'] >>>re.split(' ', 'abc mno rst') ['abc', 'mno', 'rst']
- How to split a string with a string delimiter in C#?
- How can we split a string by sentence as a delimiter in Java?
- How do we use a delimiter to split string in Python regular expression?
- Write a Python function to split the string based on delimiter and convert to series
- Java regex program to split a string with line endings as delimiter
- How to split a string in Python
- Python – Segregate elements by delimiter
- How can I use Python regex to split a string by multiple delimiters?
- How to save the str output as a string in R?
- How to use Java String.split() method to split a string by dot?
- How to split string on whitespace in Python?
- How to split a string in Java?
- How to split a string in Golang?
- How to split a semicolon-separated string to a dictionary in Python?
- Python program to split and join a string?