Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Remove Leading Zeros From A Python String With .lstrip()

Passing a zero to `.lstrip()`` will remove leading zeros instead of trimming leading whitespace

Code

original = "0001234"
    
stripped = original.lstrip('0')
    
print(stripped)

Results

1234
  • Add example of `.lstrip('w.')` or whatever for the multiple character strip.

  • Check if doing int() also strips leading zeros

  • Either way make a version that turns the string into an int