display an octal value as its string representation
问题 I've got a problem when converting an octal number to a string. p = 01212 k = str(p) print k The result is 650 but I need 01212 . How can I do this? Thanks in advance. 回答1: Your number p is the actual value rather than the representation of that value. So it's actually 650 10 , 1212 8 and 28a 16 , all at the same time. If you want to see it as octal, just use: print oct(p) as per the following transcript: >>> p = 01212 >>> print p 650 >>> print oct(p) 01212 That's for Python 2 (which you