Instance methods are simply functions written inside of a class, but they always have their first parameter named
self
. The self
parameter represents the same thing as this
in Java, and it
is set by Python—the caller does not write a corresponding argument inside the call's parentheses. For example:
class Book(object):
def print_info(self, comment):
print(self)
print(comment)
creates a method that takes one argument, a comment, and prints the book followed by the comment. It could be called like this:
book = Book()
book.print_info('(400 pages)')
Fill in the placeholders so that the actual outputs match the expected outputs.