174k views
1 vote
How do you remove a letter in python? I need to remove the letter a in whatever the user enters

2 Answers

2 votes

Answer:

str1 = input("Enter your word: ")

str2 = " "

for i in range(len(str1)):

if str1[i] not in "a":

str2+=str1[i]

print(str2)

Step-by-step explanation:

welcome.

User TerryProbert
by
4.3k points
5 votes

Answer:

One can use replace() inside a loop to check for a bad_char and then replace it with the empty string hence removing it. This is the most basic approach and inefficient on performance point of view.

Step-by-step explanation:

Call str. replace(old, new) with the character to remove as old and the empty string "" as new . Assign the resultant string to the original string's variable. Use a loop to iterate through a string of multiple specific characters and remove them

User Isioma Nnodum
by
4.2k points