Remove Character

Remove all occurrences of a character.

Logic BuildingIntermediate
Logic Building
# Take string input
s = input("Enter a string: ")
char_to_remove = input("Enter character to remove: ")

# Remove
result = s.replace(char_to_remove, "")
print(f"After removal: {result}")

Output

Enter a string: Hello
Enter character to remove: l
After removal: Heo

Replace character with empty string.

Key Concepts:

  • Replace with "" to remove
  • All occurrences removed
  • Returns new string