QUESTION IMAGE
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
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.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
myBook.title = 'To Kill a Mockingbird'