How to Remove a Character From a String in Python | EP-25 How to Remove Letters From a String
How to Remove Letters From a String in Python
Remove Characters From a String Using replace()
"""str.replace() can be used to replace all the occurrences of the desired character.
It can also be used to perform the task of character removal from a string as we can
replace the particular index with empty char, and hence solve the issue. """
string1 = "cybrosys technologies pvt ltd , calicut"
new_string = string1.replace('calicut','')
print(new_string)
Remove Letters From a String Using removeprefix()
"""removeprefix() removes the prefix and returns the rest of the string.
We can remove letters from a string for any specific index by dividing the string into
two halves such that the letter that we wanted to remove comes in the prefix of any of
the two partition and then we can apply the method to remove the letter"""
s="cybrosys"
s1=string1.removeprefix("c")
print(s1)
s2=s[:3]+s[3:].removeprefix("r")
print(s2)
#Python #PythonProgramming #LearnPython #PythonTutorial #StringManipulation #Coding #Programming #PythonTips #PythonBeginner #CodeWithMe #stringprocessing #dataCleaning #coding #programming #tutorial
Connect With Us:
—————————————
➡️ Website: https://www.cybrosys.com/
➡️ Email: info@cybrosys.com
➡️ Twitter: / cybrosys
➡️ LinkedIn: / cybrosys
➡️ Facebook: / cybrosystechnologies
➡️ Instagram: / cybrosystech
➡️ Pinterest: / cybrosys