The replace()
method can be used to remove a character or a substring from a string by replacing it with an empty string.
main.py133 chars5 lines
The split()
method can be used to split a string into a list of substrings based on a delimiter. We can use this method to split the string at the character we want to remove, and then join the list of substrings back into a string using the join()
method.
main.py170 chars6 lines
Slicing can also be used to remove a character from a string by creating a new string that includes only the characters before and after the one we want to remove.
main.py193 chars6 lines
Note: If the character is not found using index()
, the program will throw a ValueError
.
gistlibby LogSnag