Even though the type of the variable is char, I need to remove all 0s at the beginning of numbre:
0Number = "0000386489" "0000386489" --->> 386489
Or there is an integer starting with 0
You can accomplish this task in a number of ways.
Use int and str conversion operations:
txt_number = "00036"; txt_number = str(int(txt_number))
However, this only works with integers and may not be the best approach for floating point numbers.
Another method is to use the lstrip operation directly on the string.
txt_number = "0036".lstrip("0")
The above is the detailed content of How to remove 0 from first number with python. For more information, please follow other related articles on the PHP Chinese website!