成員函數和類函數

類函數;
# -*- 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:\Python27\python.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()
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章