我无法理解为什么即使在更改对象属性 self.name 和 self.author 之后,self.details 也会打印同一行。
class Book(object):
def __init__(self, name, author):
self.name = name
self.author = author
self.details = self.name + ' written by ' + self.author
bk = Book("Harry Potter", "J K Rowling")
print(bk.name)
print(bk.author)
print(bk.details) #Harry Potter written by J K Rowling
bk.name = 'Becoming'
bk.marks= 'Michelle Obama'
print(bk.name)
print(bk.author)
print(bk.details) #Harry Potter written by J K Rowling
Smart猫小萌
相关分类