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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dasazzad
    New Member
    • Jan 2016
    • 2

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

    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
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    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:
    Code:
    >>> 050
    40
    >>> 080
    Traceback (  File "<interactive input>", line 1
        080
          ^
    SyntaxError: invalid token
    >>> 0x659def
    6659567
    >>> 0b1001100011010
    4890
    >>>

    Comment

    • dasazzad
      New Member
      • Jan 2016
      • 2

      #3
      Thank you Mr. Bvdet that was helpful.

      Comment

      Working...