Python Remove First & Last Character from String

Python remove last character from string; Through this tutorial, i am going to show you how to remvove last character or letter from string.

Python Remove First & Last Character from String

There are two way to remove first and last character from string in python:

  • 1: Remove last Character from String Python
  • 2: Python Remove first Character from String

1: Remove last Character from String Python

See the example for remove last character from string in python:

# Python code to remove last character from string
# initializing test string
str='hello world!'
# Remove last character
str = str[:-1]
# Print remaining string
print(str)

Output

hello world

2: Python Remove first Character from String

See the example for remove first character from string in python:

# Python code to remove first character from string
# initializing test string
str='!my world'
# Remove first character
str = str[1:]
# Print remaining str
print(str)

Recommended Python Tutorials

Recommended:-Python Modules
Recommended:-Python Lists
Recommended:-Python Strings

Be First to Comment

Leave a Reply

Your email address will not be published.