MR_ GB
0
Q:

python remove string from string

s = 'abc12321cba'

print(s.replace('a', ''))
1
"Str*ing With Chars I! don't want".replace('!','').replace('*','')
13
s = 'ab12abc34ba'
print(s.replace('ab', ''))
4
>>> papa = 'papa is a good man'
>>> papa.replace('papa', '')
' is a good man'
1
url = 'abcdc.com'
print(url.replace('.com',''))
0
import re
url = 'abcdc.com'
url = re.sub('\.com$', '', url)
0
string = 'Hello WorldR'
# Lets say for instance you want to remove the R to display
# Hello World

print(string[:-1]) 
"""
The [:-<number of chars>] to remove from string starting from
right to left
"""
5

New to Communities?

Join the community