By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,829 Members | 1,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,829 IT Pros & Developers. It's quick & easy.

I was trying to print a simple number using this code: " print ("Test output %d" %

P: 2
Hello there,

I was trying to print a simple number using this code:

" print ("Test output %d" % 050) "

but it is giving following output

" Test output 40 "

I need this explanation why it is showing this result.

In Fact I've tried with few more code and the respective output is given below with the code.. Please Help me with the explanation..

Sample 1:
print ("Test Output %d" % 0100)
Test Output 64

Sample 2:
print ("Test Output %d" % 060)
Test Output 48

Sample 3:
print ("Test Output %d" % 020)
Test Output 16

Sample 4:
print ("Test Output %d" % 010)
Test Output 8

Sample 5: (It actually provide error)
print ("Test Output %d" % 080)
output:
print ("Test Output %d" % 080)
^
SyntaxError: invalid token
Jan 21 '16 #1

✓ answered by bvdet

The integer "050" is in octal notation and represents the decimal integer "40". "080" is invalid because there is no "8" in octal.
Examples of octal, hexidecimal and binary numeric literals:
Expand|Select|Wrap|Line Numbers
  1. >>> 050
  2. 40
  3. >>> 080
  4. Traceback (  File "<interactive input>", line 1
  5.     080
  6.       ^
  7. SyntaxError: invalid token
  8. >>> 0x659def
  9. 6659567
  10. >>> 0b1001100011010
  11. 4890
  12. >>> 

Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
The integer "050" is in octal notation and represents the decimal integer "40". "080" is invalid because there is no "8" in octal.
Examples of octal, hexidecimal and binary numeric literals:
Expand|Select|Wrap|Line Numbers
  1. >>> 050
  2. 40
  3. >>> 080
  4. Traceback (  File "<interactive input>", line 1
  5.     080
  6.       ^
  7. SyntaxError: invalid token
  8. >>> 0x659def
  9. 6659567
  10. >>> 0b1001100011010
  11. 4890
  12. >>> 
Jan 21 '16 #2

P: 2
Thank you Mr. Bvdet that was helpful.
Jan 24 '16 #3

Post your reply

Sign in to post your reply or Sign up for a free account.