Search code examples
pythoninteger

how can i delete 0 at the first of number with python


Please i need to delete all 0 in the beginning of numbre even the type of variable is char like :

Number = "0000386489"

"0000386489"  --->>  386489

or having an integer numbre with 0 at first


Solution

  • You can accomplish this with several ways.

    1. Using int and str casting operations:

      txt_number = "00036"; txt_number = str(int(txt_number))

    However, this will only work on integer numbers and may not be the best method for floating numbers.

    1. Another way is to use lstrip operation on the string directly.

      txt_number = "0036".lstrip("0")