如何将数字串转换为保留相同数字的整数?(how to convert the string of numbers into integers preserving the same digital numbers?)
如何将数字串转换为保留相同数字的整数? 例如:
ml = ['076'] print int(ml[0]) 76但我要求结果为076
How to convert the string of numbers into integers preserving the same digital numbers? for example:
ml = ['076'] print int(ml[0]) 76but i require the result as 076
最满意答案
你可以这样做:
ml = ['076'] print "%03d" % int(ml[0]) 076如果您要执行计算然后使用前导零打印结果,那么这很有用:
ml = ['076'] print "%03d" % (int(ml[0]) / 2) 038You can do this:
ml = ['076'] print "%03d" % int(ml[0]) 076That's useful if say you want to perform a calculation and then print the result with leading zeros:
ml = ['076'] print "%03d" % (int(ml[0]) / 2) 038更多推荐
发布评论