類函數;
# -*- 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()