Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
There are a lot of pieces to Python's object-oriented programming features. Let's talk about them so we can have a shared vocabulary for the rest of the course.
The class
keyword lets us define a class. We use it just like we do the def
keyword for making functions. Class definitions are blocks like function definitions.
class NewClass:
Inside of the class, variables are called attributes.
class NewClass:
name_attribute = "Kenneth"
And functions that are defined inside of a class are called methods.
class NewClass:
name_attribute = "Kenneth"
def name_method(self):
return self.name_attribute
Whenever we call a class, it creates an instance. Each instance has full access to the all of the attributes and methods of the class.
new_instance = NewClass()
new_instance.name_method()
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up