# -*- coding:utf-8 -*-
import sys
class testsqawd(object):
def hello(self):
print('the name of method is ## {} ##'.format(sys._getframe().f_code.co_name))
print('the name of class is ## {} ##'.format(self.__class__.__name__))
if __name__ == '__main__':
ttt = testsqawd()
ttt.hello()
the name of method is ## hello ##
the name of class is ## testsqawd ##
Process finished with exit code 0
本文介绍了一个简单的Python程序,该程序通过类实例调用方法来打印出方法名及所属类名。这对于理解Python中如何操作类和方法提供了一个基本示例。
1万+

被折叠的 条评论
为什么被折叠?



