# -*- coding: utf-8 -*-
class Document():
def __init__(self, title, author, context):
print('init function called')
self.name='xxx'
harry_potter_book = Document('Harry Potter', 'J. K. Rowling', '... Forever Do not believe any thing is capable of thinking independently ...')
print(harry_potter_book.name)
C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/python study/t15.py"
init function called
xxx
如果去掉__init__:
# -*- coding: utf-8 -*-
class Document():
# def __init__(self, title, author, context):
print('init function called')
self.name='xxx'
harry_potter_book = Document('Harry Potter', 'J. K. Rowling', '... Forever Do not believe any thing is capable of thinking independently ...')
print(harry_potter_book.name)
C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/python study/t15.py"
init function called
Traceback (most recent call last):
File "C:/Users/TLCB/PycharmProjects/untitled2/python study/t15.py", line 2, in <module>
class Document():
File "C:/Users/TLCB/PycharmProjects/untitled2/python study/t15.py", line 5, in Document
self.name='xxx'
NameError: name 'self' is not defined