Hello, my name is Nizar Dajani, and in these lessons, you will learn about object-oriented programming in Python. And in this lesson, you'll learn about classes and objects. Objects-oriented programming, or OOP for short, is a programming paradigm that uses the concept of objects and classes to structure and organize code. This approach encourages the creation of reusable and modular code, making it easier to manage and maintain software projects. And Python is a powerful and versatile programming language that supports OOP, which makes it an excellent choice for a wide range of applications. Now please understand though that OOP is not a language-specific programming paradigm. I can also use OOP with any other language as well, not just Python. All right, so a class in OOP is a blueprint for creating objects, and objects are instances of the class. A class also defines a set of attributes and methods that are common to all objects of that class. Objects, on the other hand, represent individual instances of a class, each with its own unique set of data and behaviors. Let's look at some code examples to better understand these concepts. In Python, a class is defined using the class keyword, followed by the class name, and a colon. Then the class body, which must be indented code, contains the attributes and methods that define the class's structure and behavior. In this example, we have defined a cat class with a class attribute called species, and a method called meow. You can think of an attribute as a variable, and a method as a function. Actually, we call a standalone function, a function, but once this function belongs to a class, then we refer to it as a method. Some programmers refer to these two terms interchangeably, but there is this distinction that I just mentioned now. And there is also a distinction between class attributes and instance attributes. Class attributes are attributes or variables that can be used by all objects that we create from the class. However, instant attributes pertain to only the instance and not the entire class. And that's why in my code example here, I have a class attribute called species, with a value of filadi. And this value will be the same for all cat instances that we create. So it's like a constant value. Now the self parameter in the meow method definition, this is a reference to the instance of the class, and I use it to access the instance attributes and methods. So this first example here just shows my class. It also shows the attribute and the method. And the meow method doesn't do much except return the string meow. Now I will just run this code cell, which will not return anything, because there is no code that calls this class yet. For the class to run, it must be called in my code. Now let's look at the second code cell together. To create an object, which I explained is an instance of a class, you simply call the class as if it were a function, and provide any required arguments. This code creates a new object of the cat class, and assigns it to the variable my cat. So now that I have an instance of the cat class, which is also an object, and so I can now access the objects attributes and methods using the dot operator as I have in my two print statements. I have my underscore cat object, followed by a dot, followed by species. Then I can also access the meow method, the cat class, because the object my underscore cat is an instance of that class. And when I run this code, I get the values back as expected. In my next code cell, I have more details added to the cat class, the first of which is this init method with double underscores on both sides. This is intentional and has a particular meaning. The init method is a special method in Python classes, and it's known as a constructor. It is called automatically when a new object is created, and is used to initialize the object's attributes with default or user supplied values. So if you notice in my first code cell, I don't have an init method. But that still doesn't mean that it's not there. Even if I don't explicitly declare this special method, it's still part of my class, and it still gets called each time I create an object of that class. And in this updated cat class, the init method takes three parameters, self, name, and age. But when creating a new cat object, you only need to provide a name and age only. Now why is that? Why don't we need to provide the self parameter, which is expected as part of the methods definition? Well, you see in Python, the self parameter is used within class methods to refer to the instance of the class, meaning the object itself. When you create a new object, you do not need to explicitly provide the self argument, because Python automatically passes the reference to the instance as the first argument when calling a method. So based on that, the self parameter is not required to be passed explicitly. In this code line, the newly created my underscore cat object, this fills in the place of the self parameter. Now to call the cat class, I call it by its name, and I need to pass it the name and age parameters as we see in this line here. I created a new object called my underscore cat, which is an instance of the cat class. And I pass it in name of body and age of three, because these are the required parameters for the code to run successfully. So this will create an object for me from the cat class and set its name as body and an age of three. Now, when the Python interpreter comes to this line of code and execute it, it will go up to the init method and begin to initialize or construct this object. For the self parameter, it will be the object itself. So it will be my underscore cat. Then for the name parameter, it will be body. And for the age, it will be three. Then we move to the instance attributes, which are self dot name, and its value is set to name. And this name value is the name parameter that is passed to the init method. And then we also create the self dot age attribute, and we set its value equal to age, which gets its value from this age parameter. So now I have created an object of the cat class. And my object is called my underscore cat, with the name attribute of body, and an age attribute of three. As for the only method in this class, meow, it again takes the self parameter. And all it does is return a string value that says the object's name, followed by the words, says meow. So let me run this code cell. And the output is buddy, three, and body says meow. So to create a class, I use the reserved word of class, followed by the class name, followed by a colon. Then comes the body of my class, which is all indented code. This means that all this indented code is part of the class. The class can have class attributes, like species. And this means that this attribute is accessible by all instances of this class. This is in contrast to these two attributes here, name and age, which are instance attributes, because they are only accessible to the instance of the class, not all the classes. And the init method is a special type of method, which is used to initialize or construct a class when we first call the class in our code. I can explicitly call it and customize the parameters and attributes. But if I don't explicitly declare it, it will still be called automatically. And the self parameter is by default the first parameter required in any method in a class. It refers to the instance being created, and it's passed by default when we call any of the classes methods, including the init method. And classes can include methods like this meow method to be called as part of this class, and return or not return any output. Now this class was first be called. I'm going to do that by using this line of code. This creates an instance of the class. And once we have the instance created, this newly created object can now use the class attributes and methods, as well as the instance attributes and methods as well. So in this lesson, you learned about the concepts of classes and objects in object oriented programming. And in the next lesson, you'll learn about inheritance in object oriented programming. Thanks for watching.