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
Answers:
You can convert it to a raw string and use replace
as normal
s = r"domainbh16"
print(s.replace("domain\", '')) #bh16
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
You can convert it to a raw string and use replace
as normal
s = r"domainbh16"
print(s.replace("domain\", '')) #bh16