Printing Queries in Python -
this question has answer here:
- what numbers starting 0 mean in python? 7 answers
i new python, in way new programming.
was trying teach myself python basics... , came across weird thing...
please find below printing results...
>>> print 1,000,000 1 0 0 >>> print 1,112,231 1 112 231 >>> print 000 0 >>> print 1,001,002 1 1 2 >>> print 1,100,001,0010 1 100 1 8
while understand 0010 binary equivalent of 8 (in last one), not understand why python so? embedded logic of language or else?
the remaining, able figure out; if can give brief explanation great!
python literals preceded '0' tells express in in octal. literals preceded '0x' hexadecimal. literals preceded '0b' binary.
print 0010 8 print 0b110011 51 print 0x100 256
i have tested '0o' on python 2.7.6 , gotten
print 0o111 # number 0 letter o followed digits 73
note python 3 print 0111 111 supposed treat leading 0 part of decimal number unless followed 'x', 'o', or 'b' not have python 3 cannot test myself.
thanks @adamsmith pointing out in comment.
Comments
Post a Comment