+ 1
A pythonic question!
Class Car: pass x = Car() print(x) print(Car()) Output is: <__main__.Car object at 0x2b5727b0bef0> <__main__.Car object at 0x2b5727b0be80> Why am I getting different memory locations? Shouldn't they be the same? Calling a method in both mentioned ways works properly and identically, so what makes any diffent in using the class name directly or assigning it to a variable? Aren't they both instantiation?
3 Answers
+ 3
When you create the car class it gets a place in the memory after instantiating x object the object receives different location cuz it's not a copy it is different object
+ 4
No, each time you call Car() you instantiate a new Car object, different then the last. It will be a different address as well
+ 2
It is a bit like
A=next(iterator)
print(next(iterator))
Bad pitfall