成员函数和类函数

类函数;
# -*- coding:utf-8 -*-
# !/usr/bin/python
class Document():
    def __init__(self, title, author, context):
      print('init function called')
      self.title = title
      self.author = author
      self.__context = context

    @classmethod
    def create_empty_book(cls, title, author):
        print cls
        return cls(title=title, author=author, context='nothing')
a=Document.create_empty_book('aa','bb')

C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/python study/t11.py"
__main__.Document
init function called


成员函数:

# -*- coding:utf-8 -*-
# !/usr/bin/python
class Document():
    def __init__(self, title, author, context):
      print('init function called')
      self.title = title
      self.author = author
      self.__context = context

    @classmethod
    def create_empty_book(cls, title, author):
        print cls
        return cls(title=title, author=author, context='nothing')
    def test(self):
        return '111'
a=Document.create_empty_book('aa','bb')
print a.test()
 
原文地址:https://www.cnblogs.com/hzcya1995/p/13348377.html