string strip in python

Question:

I would need to stripoff “domain” from “domainname” to extract name which can be any name or the word name literally

>>> s="domainname"

>>> x=s[5:]
>>> print(x)
n
ame
>>> s="domainbh16"
>>> x=s[5:]
>>> print(x)
h16
>>> x=s[4:]
>>> print(x)
ih16
Asked By: ananda

||

Answers:

You can convert it to a raw string and use replace as normal

s = r"domainbh16"

print(s.replace("domain\", '')) #bh16
Answered By: datawrestler
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.