是否可以在不创建对象的情况下访问类的方法? [英] Is it possible to access Methods of a class without creating object?

查看:78
本文介绍了是否可以在不创建对象的情况下访问类的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,


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


谢谢

PSB



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


Thanks
PSB

推荐答案


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 | < span class =codeLinkonclick =LineNumbers(this);>行号


这篇关于是否可以在不创建对象的情况下访问类的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆