Not getting exact result in python with the values leading zero. Please tell me what is going on there

前端 未结 6 687
温柔的废话
温柔的废话 2020-12-07 02:28

zipcode = 02132

print zipcode

result = 1114

6条回答
  •  一个人的身影
    2020-12-07 02:33

    leading zero means octal as other have said. one way to keep your zero is to strip the leading zeros and just use a zero padded string when you display it,

    
    >>> myInt = 2132
    >>> print myInt
    2132
    >>> myString = "%05d" % myInt
    >>> print myString
    02132
    >>> print int(myString)
    2132
    

    you probably get the idea.

提交回复
热议问题