From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Static and instance methods

Static and instance methods - Python Tutorial

From the course: Python Essential Training

Static and instance methods

- [Instructor] Let's take a look at one my favorite things to do in Python, String Parsing. I'm going to make a class called Word Set, and like its name implies, it is going to contain a set of words. So self dot words is equal to an empty set. So this set starts out empty, and as we go, we can add to it. To add to it, I just want to pass in big blocks of text. Like many programmers, I'm fairly lazy, and I don't want to have to clean my text, or do anything special before I pass it in, so I'm just going to pass it in, punctuation, and all. Word set, it's going to be equal to new word set. Word set, dot, add text. Hi, I'm, let's escape that, escape that apostrophe there. Here is a sentence I want to add, then word set dot add text. Let's make another sentence. Here is another sentence I want to add, period. Okay, so obviously we need to write a method here called add text, and that's going to take in self and some…

Contents