Last modified: Feb 15, 2023 By Alexander Williams
Remove first character from string in Python
Let’s say you have a string, and you want to remove the first character from it.
How can you do that?
syntax
print(string[1:])
example 1: remove the fist characters from a string
#remove the first character from a string Python
#string
string = 'hello'
#remove the first character from a string
print(string[1:])
output
ello
As you can see the "h" character has been removed from the string
example 2: remove the two fist characters from a string
#remove the two first characters from a string Python
#string
string = 'hello'
#remove the first character of a string
print(string[2:])
output
llo
done! "h" and "e" characters has been removed