In this lecture I'm going to talk about Python classes. The contents of this lecture include what is class class terminology and features and will give you an example of a class. A class is a fundamental tool in object oriented programming language that allows you to create objects with related data and functions, and perform tasks with those data. A class has a name, and attribute and methods to operate on data. An example of a class name is a calculator class. And it can have an attribute of a math calculation.
It also can have an addition method to add numbers together. And you can pass three and two as data to that method to be operated on later on. This module of explaining class is called encapsulation module. The basic syntax of a class is as follows, you write the term class followed by a name And colon, then is followed by your methods and blocks of code and a return function. Then in order to call a method from a class to operate on data, you write down the name of the class followed by a date and the method, then write the data in between parentheses. To create a simple class, you write down class, followed by a name.
Here we use user and colon, then we pass it the term pass, which is a statement that doesn't do anything. So this user class doesn't do anything at the moment. To create class instances. what you've got to do is to write down the name of the instance for example user one and assign it to the class. So write down the class name followed by parentheses. So we create two user instances here, we assign them to the user class.
User instances are also referred to as fields that can hold data so we can assign data to them later on. In order to pass data to class attributes, we write down the name of the instance, dot a variable, and then assign data to it using assignment operator. Here we assign first name and last name to buff user instances. To do so you write down user one dot first name equals a name. The first name here is actually a variable within the instance of the class. The last name is also a variable of the user.
One instance of the class we can also assign data to the same two variables have the second class instance, which is the second user. So write down user to dot first name equals Alan, let's say user to dot last name equals West. We can also call these data back from the class instances by using print function in order to get class outputs you write down print, and in between parentheses write down the name of the instance, dot the name of the variable. So you can do that for all of the variables of all of the instances, or those that you need them. Here, we need first and last name, or the first user. And the first and last name of the second user, we use two different print functions in order to separate them.
Mark Brown was the first user's first and last name. And alan west was the first and last name of the second user. So this is a simple way of creating class class instances and variables, and also assigning data to them. In the next coming lecture. I'm going to talk about class features and I'll show an example.