How to remove the last part of a string by substring in Python

1 Answer

0 votes
s = "python programming"
print(s)
s = s.rstrip("ming")
print(s)
 

s = "python programXming"
print(s)
s = s.rstrip("ming")
print(s) 
 
 
 
'''
run:
 
python programming
python progra
python programXming
python programX
 
'''

 



answered Feb 5, 2021 by avibootz
...