To get the substring after a specific character in Python, you can use slicing to extract the substring after the specified character.
In this example,
url
with a value of "https://example.com/page"
.'/'
using index
.url = 'https://example.com/page'
substring = url[url.index('/') + 1:]
print('Substring after "/":', substring)
Substring after "/": /example.com/page
In this example,
str
with a value of "Hello,World"
.','
using index
.str = 'Hello,World'
substring = str[str.index(',') + 1:]
print('Substring after ",":', substring)
Substring after ",": World
In this tutorial, we learned How to get Substring after Specific Character in Python language with well detailed examples.