[Tutor] Octal confusion, please explain why. Python 3.2

Alan Gauld alan.gauld at btinternet.com
Sat Jun 2 14:59:54 CEST 2012


On 02/06/12 12:29, Jordan wrote:

> think it is because they are transported around within python as a
> integer value, is this correct and if so why?

Steven has already answered your issue but just to emphasise
this point.

Python stores all data as binary values in memory. Octal,
decimal, hex are all representations of that raw data.

Python interprets some binary data as strings, some as integers, some as 
booleans etc and then tries to display these objects in a suitable 
representation. (We can use the struct module to define the way python 
interprets binary data input.) For integers the default is base 10 but 
we can exercise some control over the format by using modifiers such as 
oct() hex() etc.

But these functions only change the representation they do not change 
the underlying data in any way.

HTH,

Alan G.





More information about the Tutor mailing list