且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以在不创建对象的情况下访问类的方法?

更新时间:2022-01-14 00:17:04


HI,


是否可以在不创建对象的情况下访问类的方法?


谢谢

PSB


Is it possible to access the Methods of a class without creating object?


Thanks
PSB



Python手册说:

类实例方法是绑定的还是非绑定的,指的是方法是分别通过实例还是类访问。当方法未绑定时,其im_self属性将为None,如果调用,则必须将显式自身对象作为第一个参数传递。在这种情况下,self必须是未绑定方法的类(或该类的子类)的实例,否则会引发TypeError。


2.3.10其他内置类型子2.3.10.4方法(版本2.4.4)

The Python Manuals says:
Class instance methods are either bound or unbound, referring to whether the method was accessed through an instance or a class, respectively. When a method is unbound, its im_self attribute will be None and if called, an explicit self object must be passed as the first argument. In this case, self must be an instance of the unbound method''s class (or a subclass of that class), otherwise a TypeError is raised.

in section 2.3.10 Other Built-in Types sub 2.3.10.4 Methods (version 2.4.4)



HI,


是否可以在不创建对象的情况下访问类的方法?


谢谢

PSB


Is it possible to access the Methods of a class without creating object?


Thanks
PSB



您可以访问类方法而无需创建类实例。

You can access class methods without creating a class instance.

展开 | 选择 | Wrap | 行号



您可以访问类方法 w不创建类实例。
You can access class methods without creating a class instance.
展开 | 选择 | Wrap | 行号