type.__new__() takes exactly 3 arguments (0 given)

Viewed 1345

I am learning python, I found something interesting with class.

In python docs, the classes are inherited from types, so i think

class person(type):
    name = 'kevin'
p = person()
print(p.name)

should be same with

class person:
    name = 'kevin'

but actually running first code, I got mistake

TypeError: type.__new__() takes exactly 3 arguments (0 given)

running the second code no mistake, can anyone explain ? thank you`

1 Answers

Inheriting from type makes it a metaclass. Remove type as the Base class.

class person():
    name = 'kevin'
p = person()
print(p.name)

> kevin
Related