What Are Objects And Classes?2:45 with Kenneth Love
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.
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.
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()
You need to sign up for Treehouse in order to download course files.Sign up