mercredi 26 octobre 2016

Removing all zeros in string of numbers Python

Without using any built in functions, does anyone have any insight into how I could do this? Newbie to Python

Suppose we had x = "010204". Then we'd want 124 at the end.

I was thinking of a for loop that goes along the lines of:

for i in range(0,len(x)):  
    if x[i] == "0":  
        x[i] = ""  
    else x[i] = x[i]

(I don't know what you do if you don't want the string to be changed)

Aucun commentaire:

Enregistrer un commentaire