python – How to remove all zeros from an integer?

Question:

There is a random number, let's say 100403 . It is necessary to remove all zeros from it, that is, get 143 .

Answer:

I think replace will suit you.

q = str(100403)
w = int(q.replace('0', ''))
Scroll to Top