Python cut string after the character | Example code

Use the split() method to cut string after the character in Python. This split method returns the list of separated subtrings.

Python cut string after the character and Print example

Simple example code cut after “-” char in a given string. Must max split value 1 to split the string at the first occurrence of sep into a list.

Access this list’s 1 index element value to get a string with everything after the sep character.

s = "Python Programing - code example"
res = s.split("-", 1)[1]
print(res)

Output:

Python cut string after the character

Do comment if you have any doubts and suggestions on this Python char string topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.