In this section, we will take a brief look at instance methods and cover class methods in detail.
In this exercise, we will implement the navigate() and clear_history() methods for the WebBrowser class we defined in the previous section:
Add the navigate() method to the WebBrowser class:
class WebBrowser: def __init__(self, page): self.history = [page] self.current_page = page self.is_incognito = False def navigate(self, new_page): self.current_page = new_page if not self.is_incognito: self.history.append(new_page)
Any call to navigate will the set the browser's current page to the new_page argument and then add it to the history if we're not in incognito mode (incognito mode in browsers prevents browsing history from being recorded).
Calling navigate() on an instance should change current_page:
>>> vivaldi = WebBrowser("gocampaign.org") >>> vivaldi...