使用和不使用 __init__() 的正确参数创建 class 的实例有什么区别?

What is the difference creating an instance of a class with and without the correct parameter of __init__()?

我打印了两个实例,正确的以 <main.Book 开头,错误的 init() 参数开始使用 class 'main.Book'。我可以知道 difference/purpose 是什么吗?

class Book:
    def __init__(self, title):
        self.title = title

book1 = Book("Lion King") 
book2 = Book  #Doesn't have the right parameter as title not included? 

print(b1)  #<__main__.Book object at 0x10cad5c10>
print(b2)  #<class '__main__.Book'>

提前致谢!

book1 = Book("Lion King") 创建 class Bookinstance 因为 Book("Lion King") 是 class Book 的构造函数。

book2 = Bookbook2 分配给 class Book,因为 Book 是 class 而不是方法

变量“book1”是一个已初始化的 class,存储在您的 RAM 中的 0x10cad5c10 处。变量“book2”不是初始化的 class 而是一个别名。你可以这样初始化它:

aBook = book2("a Title")

不同之处在于第一个条件已初始化并存储在您的 RAM 中的某个地址,而在第二个情况下它没有被初始化 - 它只是别名。

第二种情况只是创建对象并为该实例提供一个值。