Everything is an object in python - object class and type class

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jun 3 04:08:54 EDT 2015


On Wednesday 03 June 2015 03:59, BartC wrote:

> Javascript primitives include Number and String.
> 
> What does Python allow to be done with its Number (int, etc) and String
> types that can't be done with their Javascript counterparts, that makes
> /them/ objects?

That's a good question, and I'm not sure whether or not the answer is 
"nothing, it's just an implementation detail".

I don't *think* it is an implementation detail, but I don't know enough 
about Javascript to be sure. I can see that you can include Numbers in an 
object without explicitly boxing them:

js> var foo = 23;
js> typeof foo;  
number
js> var bar = {1: foo};
js> typeof bar[1];
number


I can also see that you can explicitly box numbers inside objects:

js> var a = 42;
js> var b = new Number(42);
js> a == b;
true
js> a === b;
false
js> typeof a;
number
js> typeof b;
object


But I don't know enough to tell the practical differences between them.



-- 
Steve




More information about the Python-list mailing list