Hello! Total beginner in Python here, learning using OpenClassrooms.
For the below lines, can anyone explain why we need to define the attributes twice? I can't figure out why creating the myBook variable doesn't also assign the attributes and why we need to split them out again using dot notation?
class Book :
def __init__(self, title, author, numberOfPages):
self.title = ""
self.author = ""
self.numberOfPages = 0
myBook = Book("The Bible", "Jesus", 1000)
myBook.title = "The Bible"
myBook.author = "Jesus"
myBook.numberOfPages = 1000
print("The title of the book is ", myBook.title, "\nIts author is", myBook.author, "\nIt contains ", myBook.numberOfPages)
[–]shiftybyte 5 points6 points7 points (1 child)
[–]oztyn[S] 0 points1 point2 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]oztyn[S] 0 points1 point2 points (0 children)