
Sometimes, we want to remove leading zeros (0s) from a string like “00098” becomes “98” only. In Python, there are several ways to do this. We will be discussing some of them in this article.
"00921" --> "921"1. The int() method to remove leading zeros in Python
You can use the Python int() method to remove leading zeros from a string like this-
my_string = "000213"
my_string = int(my_string)
print(my_string)Output:

The first method is the int() method, which converts a string into an integer. While converting, it will automatically remove leading zeros in the string. Note that the string should only contain numbers and no letters, alphabets, or other symbols.
2. The lstrip() method to remove leading zeros
The strip() method takes a string argument. This method will remove the string given as the argument from the string in operation. When used, it automatically removes leading zeros ( only ) from the string. Note that this works for numbers and all characters accepted as a string. However, another method strip() will remove the leading and ending characters from the string. Python lstrip() docs.
You can use the Python lstrip() method to remove leading zeros from a string like this-
my_string = "00913"
my_string = my_string.lstrip('0')
print(my_string)Output:

3. Reassigning until the character in the 0th index is “0”:
In this method, we will loop through a string and check whether the string’s first character is “0”. If the first character is “0,” then we will reassign the string from the first index. This is fairly simple and can be understood by looking at an example.
You can use the reassigning method to remove leading zeros from a string like this-
my_string = '0002134'
for i in my_string:
if i == '0':
my_string = my_string[1:]
print(my_string)Output:

Output for the method of reassigning until the character in the 0th index is “0”
4. The startswith() method:
In this method, we will loop through a string and check whether the string’s first character is “0” with the startswith() method. This will return a boolean value, and we will use the same concept from 3rd way.
You can use the Python startswith() method to remove leading zeros from a string like this-
my_string = "00023"
for i in my_string:
if i == "0":
my_string = my_string[1:]
print(my_string)
>> 23
my_string = "00023"
for i in my_string:
if i == "0":
my_string = my_string[1:]
print(my_string)
>> 235. Using regex (Regular Expression) to remove leading zeros in Python string:
Python has a built-in Regular Expression module, namely, “re.” We can also remove the leading zeros from a string of numbers using this module. This is a simple task and can be understood once the code looks at.
The code:
import re
regex = "^0+(?!$)"
str = "000782"
str = re.sub(regex, "", str)
print(str)Output:

Possible Reasons to remove leading zeros or trailing zeros from a number or a string?
- For formatting time – 01:24 to 1:24
- For stripping IP Address
- For stripping units of data: 4000 to 4K
Checkout Short Video:
Keep Learning, Keep Coding
Also Read:
- You Can Now Run AI Fully Offline on Your Phone — Google’s Gemma 4 Just Changed Everything
- I Built a 24×7 AI Blogging System for WordPress Using Python (Free) — Full Code Inside
- This Reddit User “Hacked” AI With Simple Tricks… And The Results Are Insane
- One “rm -rf” Command Almost Wiped Out $100 Million Worth of Toy Story 2
- How to Make Money with ChatGPT in 2026: A Real Guide That Still Works
- PicoClaw vs OpenClaw: The Tiny AI That Could Replace Powerful AI Agents
- Oracle Layoffs 2026: People Woke Up to an Email… and Lost Their Jobs Instantly
- X’s New Video Update Is Breaking a Basic Feature — And Users Are Not Happy
- The Most Shocking Military Tech Yet: Robot Soldiers That Could Change Warfare Forever
- Sora Shutdown: The Reality Check That Shook AI Video — And What Comes Next
- Aya Expanse supports multiple languages for diverse global applications
- Alibaba releases Page Agent on GitHub for public access
- Google Sheets Gemini reaches new levels of performance and accuracy
- Artificial intelligence boosts cardiac care in rural Australian communities
- NVIDIA GTC 2026 Offers Insights into Future Artificial Intelligence Developments
- Google DeepMind Updates Satellite Embedding Dataset with 2025 Data
- Enhancing hierarchical instruction in advanced large language models
- Meta supports community development near its data centers through grants
- Exploring the world of underwater robotics through coding techniques
- ABB Robotics partners with NVIDIA for large scale physical AI solutions
- Why All AI Models Are Slowly Becoming the Same Model
- Aam Aadmi vs Corrupt System: How ChatGPT Helped One Guy Expose Govt Fraud, The Story: “Ravi and The Missing Light Pole”
- ChatGPT Asked a person to commit suicide to solve the problem
- Viral Moment: China’s AgiBot X2 Makes History With World’s First Webster Backflip
- Terminator Rising: Albania Hands Power to AI, Echoing a Nightmare of Human Extinction
- What Is Albania’s World-First AI-Generated Minister and How Does It Work?
- Does ChatGPT believe in God? ChatGPT’s Personal Opinion
- ChatGPT vs Human: The Breath-Holding Chat That Ends in “System Failure”
- What Is Vibe Coding? The Future of No-Code Programming and Its Impact on Software Developers
- Struggling to Generate Ghibli-Style AI Images? Here’s the Real Working Tool That Others Won’t Tell You About!


