-3

Consider the following:

class car:
    pass
tesla=car()

When I do type(tesla), this gives __main__.car, as I expect. But if I have:

class car:
    pass
tesla=car

then type(car) gives type.

From another post here on SO, it really shouldn't matter how I instantiate the class. But clearly as we see here, the type of the object is different. I am an absolute beginner to python, could you please let me know what is going on here.

Thanks!

prananna
  • 31
  • 5

1 Answers1

3

In the second case, you're not instantiating the class, just giving it another name, tesla. The parentheses are required for instantiation.

wjandrea
  • 28,235
  • 9
  • 60
  • 81