How to remove leading and trailing zeros in a string? Python

后端 未结 6 2030
庸人自扰
庸人自扰 2020-11-28 06:42

I have several alphanumeric strings like these

listOfNum = [\'000231512-n\',\'1209123100000-n00000\',\'alphanumeric0000\', \'000alphanumeric\']
6条回答
  •  旧时难觅i
    2020-11-28 07:12

    You can simply do this with a bool:

    if int(number) == float(number):
    
       number = int(number)
    
    else:
    
       number = float(number)
    

提交回复
热议问题