Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

Removing the First Character From String in Python

  • 21 Aug, 2025
  • Com 0
How to Remove the first character from a string in Python

The most efficient and Pythonic way to remove the first character from a string is by starting the slice from index 1 and leaving the end index empty to include all remaining characters.

Slicing a string to remove the first character from a string

 

my_string = "Apple"

print(my_string)

# Output: Apple

# Removing the first character
new_string = my_string[1:]

print(new_string)

# Output: pple

In this code, my_string[1:] means we are slicing the string from index 1 and going till the end of the string. The 0th index (H) is left out, which effectively strips the first character.

The time complexity is O(n), where n is the string length (creates a new string).

Alternate ways

Using str.removeprefix() (Python 3.9+)

Using str.removeprefix() method

Python 3.9 introduces the str.removeprefix() method that removes the specific prefix if it exists, not just any first character.

What we need to do is pass the first character of the string to the str.removeprefix() method, and it returns a new string with that character stripped.

text = "Apple"

result = text.removeprefix(text[0])

print(result)

# Output: pple

If the character you are trying to delete does not exist, it won’t throw any error; instead, it returns an unchanged string.

Using lstrip()

Using lstrip() function to remove the first character from a string

The lstrip() method removes leading characters if they match a specified set (not just one character).

my_string = "Apple"

print(my_string)

# Output: Apple

new_string = my_string.lstrip(my_string[0])

print(new_string)

# Output: pple

The lstrip() method accepts an argument to strip from a string, and in our case, it is the first character denoted by my_string[0].

When using lstrip(), keep in mind that if your input string is “AAAple” and you want to remove the character “A”, it will remove all three “A”.

So, in this case, it does not remove the first character; it removes the first three characters. So, use it with caution.

triple_string = "AAApple"

print(triple_string)

# Output: AAApple

stripped_string = triple_string.lstrip(triple_string[0])

print(stripped_string)

# Output: pple

As you can see from the output, all three A’s are gone,

Using re.sub()

Using re.sub() method to remove the first character

The re.sub() function performs a search and replace operation on strings. In this case, the regular expression ‘^.’ is used, where the caret ^ denotes the start of the string, and the dot (.) matches any single character.

It is useful when you need more complex pattern matching.

import re

my_string = "Apple"

print(my_string)

# Output: Apple

# Regular expression '^.' matches the first character of the string
new_string = re.sub('^.', '', my_string)

print(new_string)

# Output: pple

That’s all!

Post Views: 36
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Remove an Element from an Array in JavaScript
How to Split an Integer into a List of Digits in Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend