Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

you defined a book data type. class book: title = \\ author = \\ pages …

Question

you defined a book data type.
class book:
title = \\
author = \\
pages = 0

then, you created an instance of your book.
mybook = book()

which statement assigns a value to the title?
mybook.book.title = mybook.title = to kill a mockingbird
mybook.title(to kill a mockingbird)
mybook.title = to kill a mockingbird
title = to kill a mockingbird

Explanation:

Brief Explanations

In Python, to assign a value to an instance - attribute (in this case, the title attribute of the myBook instance of the book class), we use the syntax instance_name.attribute_name = value. The correct way to assign the string "To Kill a Mockingbird" to the title attribute of the myBook instance is myBook.title = 'To Kill a Mockingbird'. The first option has incorrect double - reference (myBook.book.title), the second option treats title as a function which it isn't in this context, and the fourth option only assigns a value to a local variable title and not to the title attribute of the myBook instance.

Answer:

myBook.title = 'To Kill a Mockingbird'