Why does instanceof return false for some literals?

Primitives are a different kind of type than objects created from within Javascript. From the Mozilla API docs: var color1 = new String(“green”); color1 instanceof String; // returns true var color2 = “coral”; color2 instanceof String; // returns false (color2 is not a String object) I can’t find any way to construct primitive types with … Read more

Why is [] faster than list()?

Because [] and {} are literal syntax. Python can create bytecode just to create the list or dictionary objects: >>> import dis >>> dis.dis(compile(‘[]’, ”, ‘eval’)) 1 0 BUILD_LIST 0 3 RETURN_VALUE >>> dis.dis(compile(‘{}’, ”, ‘eval’)) 1 0 BUILD_MAP 0 3 RETURN_VALUE list() and dict() are separate objects. Their names need to be resolved, the … Read more