How to remove the first character of a string in Python
In this tutorial, we are going to learn about how to remove the first character of a given string in Python.
Removing the first character
To remove the first character of a string, we can use the slice notation
[ ] with
1: as an argument in Python.
Here is an example, that removes the first character
H from the following string:
str = "How are you" print(str[1:])
"ow are you"
Similarly, we can also use the
lstrip() method by passing the first character as an argument to it.
str = "How are you" print(str.lstrip("H")); # "ow are you"
name = "oprah" print(name.lstrip("o")) # "prah"