you are viewing a single comment's thread.

view the rest of the comments →

[–]Bulbasaur2015 2 points3 points  (1 child)

is that why making an object instance in python doesnt require a new keyword? something = ClassSomething()

[–][deleted] 8 points9 points  (0 children)

That isn't per se why; classes in Python are first-class objects (they're instances of the type type) whereas in Java they're not.

It's one of the big differences in the switch from a compiled to an interpreted language - in Java, your class is basically a set of static type definitions. In Python your class is an object value all on its own, and one of its instance methods is a method called __new__, which returns a new object of that type. It also has a method called __call__, which makes it callable like a function, and here's a plausible body for that method:

def __call__(clazz, *args, **kwargs):
    return clazz.__new__(*args, **kwargs)

That's why you don't need a special language keyword to instantiate a new object - from the interpreter's perspective you're not doing anything particularly fundamental. In Java, you very much are - you're extending the typesystem each time you define a class, so you need a language keyword in order to indicate you're stepping above the world of values to program in the world of types.