Welcome back to Intermediate Python. This is the second course in the Python Scripting for DevOps Specialization. In this module, we want to look at developing classes. This is the third module of this course. In our previous module, we looked at how we model classes. This is going to give us a lot of extra functionality in our Python as we can abstract data to the class level, and a class can hold attributes and methods as we saw in our previous module. Some learning objectives here. By the time you're done with this module, I want you to be able to implement a class in Python. I want you to be able to implement the fields in the class in Python. You should also be able to implement the methods in a class in Python. Lastly, I want you to be able to implement one-to-one has-a relationships in Python. If you remember back to our last module, we talked about two relationships, has-a and is-a. We'll deal with is-a later, and how we code it. Here, we want to think about the one-to-one has-as, we'll add collections later. Lesson 1, we're going to think about how do we code a class' data fields, and properties. Just a little refresher on classes and objects. An object is a self-contained unit that has fields, methods, and other members. A class contains the code that defines the members of an object. An object is an instance of a class, and the process of creating an object is what we call instantiation. One of the three most important parts of object-oriented programming is what we call encapsulation. Encapsulation is the idea that you control the data and operations within a class that are exposed to other classes. What we want to do is hide the implementation so that we're free to change it without forcing people who use our classes to change their code. First off, if you want to add a class to a project, you just create a file with the name of the class and the.py extension. Now, that's not really required in Python. It's a convention to have the name of the class and the file be the same. In Visual Studio Code, you can click on the project and explore and add a new file. Essentially, when you create class, you'll have the shell that you see to the right here. You just see the keyword class, followed by the name of your class. By convention, we uppercase names of classes and we follow it with a colon, and then we have our class members. Basically, a field will be public by default, and it represents a data value associated with an object instance. In this case, I've got a field called myCode. I just put it after the class name and a colon, and I'm initializing it to an empty string. With the idea of encapsulation, we want to separate out fields from properties. Essentially, a property represents a data value associated with an object. Just like a field, but we're separating those two. Here you'll see we underscore twice an instance variable. Here instead of having myCode be the variable name, we have the double underscore, and then we define a getter and a setter. Sometimes we call those mutators and accessors. The getter allow someone to get the value of myCode. The setter allows them to set the value of myCode. You'll see that in the getter implementational all I do is return self is the instance of the class, and the underscore, underscore myCode. When I set it, I'm just setting it to whatever the value that's passed in. At the very bottom, I have this ability to link the get method and the set method as a property. I just say property, get_myCode, set_myCode. Basically, I'm turning those methods into properties in Python. Python is a little bit more freewheeling when it comes to object-oriented code than other languages, it gives an afterthought essentially. Just a little reminder on our last module, we talked about visibility. We want to specify the visibility of a class member are attributes or methods. We have three main visibilities. We have public, which means the field or method can be accessed from any place. Private, which means it can only be accessed within the same module or class, and protected, which means it can be accessed from the same class or derived class. We'll talk more in future lessons and modules about derived classes or specialized classes. A little review for Lesson 1. An object is a self-contained unit that has properties, methods, and other members. A class contains the code that defines the members of an object, and encapsulation lets you control the data and operations within a class that are exposed to other classes. See you soon.