ch06
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# oop/super.implicit.py
|
||||
class Book:
|
||||
|
||||
def __init__(self, title, publisher, pages):
|
||||
self.title = title
|
||||
self.publisher = publisher
|
||||
self.pages = pages
|
||||
|
||||
|
||||
class Ebook(Book):
|
||||
|
||||
def __init__(self, title, publisher, pages, format_):
|
||||
super().__init__(title, publisher, pages)
|
||||
# Another way to do the same thing is:
|
||||
# super(Ebook, self).__init__(title, publisher, pages)
|
||||
self.format_ = format_
|
||||
|
||||
|
||||
ebook = Ebook(
|
||||
'Learn Python Programming', 'Packt Publishing', 500, 'PDF')
|
||||
print(ebook.title) # Learn Python Programming
|
||||
print(ebook.publisher) # Packt Publishing
|
||||
print(ebook.pages) # 500
|
||||
print(ebook.format_) # PDF
|
||||
|
||||
|
||||
"""
|
||||
$ python super.implicit.py
|
||||
Learn Python Programming
|
||||
Packt Publishing
|
||||
500
|
||||
PDF
|
||||
"""
|
||||
Reference in New Issue
Block a user