1. Learn
  2. /
  3. Courses
  4. /
  5. Software Engineering Principles in Python

Exercise

Writing a non-public method

In the lesson, we covered how to add functionality to classes using non-public methods. By defining methods as non-public you're signifying to the user that the method is only to be used inside the package.

In this exercise, you will define a non-public method that will be leveraged by your class to count words.

Instructions

100 XP
  • Counter from collections has been loaded into your environment, as well as the function tokenize().
  • Add a method named count_words as a non-public method.
  • Give your non-public method the functionality to count the contents tokens attribute using Counter().
  • Utilize your new function in the __init__ method.