Get startedGet started for free

Creating a grandchild class

In this exercise you will be using inheritance to create a Tweet class from your SocialMedia class. This new grandchild class of Document will be able to tackle Twitter specific details such as retweets.

This exercise is part of the course

Software Engineering Principles in Python

View Course

Exercise instructions

  • Complete the class statement so that Tweets inherits from SocialMedia. SocialMedia has already been loaded in your environment.
  • Use super() to call the __init__ method of the parent class.
  • Define retweet_text. Use help() to complete the call to filter_lines with the correct parameter name. filter_lines has already been loaded in your environment.
  • return retweet_text from _process_retweets as an instance of SocialMedia.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define a Tweet class that inherits from SocialMedia
class Tweets(____):
    def __init__(self, text):
        # Call parent's __init__ with super()
        ____
        # Define retweets attribute with non-public method
        self.retweets = self._process_retweets()

    def _process_retweets(self):
        # Filter tweet text to only include retweets
        retweet_text = filter_lines(self.text, ____='RT')
        # Return retweet_text as a SocialMedia object
        return ____(retweet_text)
Edit and Run Code