An Understanding of Objects and Classes with Details

Object-Oriented Programming in Python: Aided with Diagrams An Understanding of Objects and Classes with Details
8 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46
List Price:  €64.41
You save:  €18.40
£38.50
List Price:  £53.91
You save:  £15.40
CA$69.58
List Price:  CA$97.41
You save:  CA$27.83
A$76.10
List Price:  A$106.55
You save:  A$30.44
S$66.06
List Price:  S$92.49
You save:  S$26.42
HK$388.60
List Price:  HK$544.07
You save:  HK$155.47
CHF 43.25
List Price:  CHF 60.56
You save:  CHF 17.30
NOK kr548.23
List Price:  NOK kr767.56
You save:  NOK kr219.33
DKK kr343.21
List Price:  DKK kr480.52
You save:  DKK kr137.31
NZ$83.69
List Price:  NZ$117.18
You save:  NZ$33.48
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.45
৳5,962.77
List Price:  ৳8,348.35
You save:  ৳2,385.58
₹4,203.71
List Price:  ₹5,885.53
You save:  ₹1,681.82
RM218.89
List Price:  RM306.47
You save:  RM87.57
₦82,070.58
List Price:  ₦114,905.38
You save:  ₦32,834.80
₨13,861.09
List Price:  ₨19,406.64
You save:  ₨5,545.54
฿1,686.81
List Price:  ฿2,361.67
You save:  ฿674.86
₺1,712.24
List Price:  ₺2,397.27
You save:  ₺685.03
B$288.14
List Price:  B$403.42
You save:  B$115.28
R886.41
List Price:  R1,241.05
You save:  R354.63
Лв90.03
List Price:  Лв126.05
You save:  Лв36.02
₩68,895.20
List Price:  ₩96,458.79
You save:  ₩27,563.59
₪186.25
List Price:  ₪260.77
You save:  ₪74.51
₱2,910.76
List Price:  ₱4,075.30
You save:  ₱1,164.54
¥7,626.43
List Price:  ¥10,677.61
You save:  ¥3,051.18
MX$1,006.17
List Price:  MX$1,408.72
You save:  MX$402.55
QR181.95
List Price:  QR254.74
You save:  QR72.79
P668.87
List Price:  P936.47
You save:  P267.60
KSh6,436.71
List Price:  KSh9,011.91
You save:  KSh2,575.20
E£2,444.96
List Price:  E£3,423.14
You save:  E£978.18
ብር6,117.36
List Price:  ብር8,564.80
You save:  ብር2,447.43
Kz45,590.88
List Price:  Kz63,830.88
You save:  Kz18,240
CLP$48,067.30
List Price:  CLP$67,298.07
You save:  CLP$19,230.76
CN¥355.82
List Price:  CN¥498.18
You save:  CN¥142.36
RD$3,004.58
List Price:  RD$4,206.65
You save:  RD$1,202.07
DA6,671.07
List Price:  DA9,340.03
You save:  DA2,668.96
FJ$113.87
List Price:  FJ$159.43
You save:  FJ$45.56
Q385.65
List Price:  Q539.94
You save:  Q154.29
GY$10,439.34
List Price:  GY$14,615.91
You save:  GY$4,176.57
ISK kr6,831.13
List Price:  ISK kr9,564.13
You save:  ISK kr2,733
DH491.88
List Price:  DH688.67
You save:  DH196.79
L894.84
List Price:  L1,252.84
You save:  L358
ден2,832.69
List Price:  ден3,965.99
You save:  ден1,133.30
MOP$399.42
List Price:  MOP$559.22
You save:  MOP$159.80
N$878.21
List Price:  N$1,229.56
You save:  N$351.35
C$1,836
List Price:  C$2,570.55
You save:  C$734.54
रु6,713.01
List Price:  रु9,398.75
You save:  रु2,685.74
S/188.17
List Price:  S/263.46
You save:  S/75.28
K199.92
List Price:  K279.90
You save:  K79.98
SAR187.75
List Price:  SAR262.87
You save:  SAR75.11
ZK1,328.53
List Price:  ZK1,860.04
You save:  ZK531.51
L228.84
List Price:  L320.40
You save:  L91.55
Kč1,166.86
List Price:  Kč1,633.70
You save:  Kč466.83
Ft18,787.20
List Price:  Ft26,303.58
You save:  Ft7,516.38
SEK kr534.04
List Price:  SEK kr747.70
You save:  SEK kr213.65
ARS$49,430.79
List Price:  ARS$69,207.07
You save:  ARS$19,776.27
Bs344.81
List Price:  Bs482.76
You save:  Bs137.95
COP$218,827.49
List Price:  COP$306,375.99
You save:  COP$87,548.50
₡25,565.20
List Price:  ₡35,793.32
You save:  ₡10,228.12
L1,258.85
List Price:  L1,762.49
You save:  L503.64
₲394,828.52
List Price:  ₲552,791.53
You save:  ₲157,963
$U2,059.62
List Price:  $U2,883.63
You save:  $U824.01
zł200.29
List Price:  zł280.43
You save:  zł80.13
Already have an account? Log In

Transcript

Hi and Hello everyone. This is the second video of the series objects and classes in Python. In the earlier video, we discussed about the topics to be covered in this series. For example, object oriented programming in Python, class inheritance, multiple inheritance, and operator overlapping. We also discussed the programming approach in Python that is discussed about object oriented programming, and also gave you a few details about how that is executed in Python. In this video, we'll be discussing more about class and objects.

What is a class, a class has all the details of the object, whether it would be attribute or behavior. Generally attributes are those things that remain same. For example, for example, if we create a class about the cat, so one of the attribute could be animal, this attribute would remain same for all the objects that we created from this This class of cat because the cat would not like would not be anything else other than an animal. However, there could be different methods and different other attributes that could be changing for the class cat. Now, that is, for example, the cats, they would have different names, they would have different colors, they might have different running speed, and they might have different behavior towards different people. So, these would be different things that the class would have.

But as you saw that, there could be like different types of attribute, one attribute is the class attribute that is going to remain same throughout all the objects that we create from the class. So, coming back to the class, how would you distinguish between an object and an A class? Now the class is the blueprint of the object, it has all the descriptions of the object that would be created from the class. Now, what is an object? An object is the instantiation of the class. So many Create a class we are actually defining what would be the details of the description that would be needed for the objects that would be created from the class and when we create the object what we are doing is just defining the names and the values of the variables or the attributes and methods for that we defined in the data we gave in the class and we are just giving it when you when we are creating the object.

So what we do actually, when we are creating object, for example, we did a class at and when we are creating object we gave, get one, get to get three. For example, if it had a different name to the object would be like Tom, the other name could be like Johnson, or anything that you would like to give the name of the object, but not now got some idea of what the classes and what the object in class what the syntax is going to be. The class syntax is very simple. We name we use a keyword class and the name of the class that could be anything And then there are two round brackets and then a colon. The past year you know are that the difference between passing the comment comment or non executable period as the passive executable however, generally it when the past is used to give when we when when we are going to write the code for it, but at the moment we have not written any code we use pass an instance attribute which is discuss the instance attribute that is it is going to remain same throughout all the objects that are created from the class and after that now, in method there are actually two different types of methods.

One is the method that is executed as soon as we just use that object created from the class. For example, I created this method def in itself and print nice we have a cat. Now, what will happen whenever we get into now, here I created an object Dom with this class, named get okay now, when I When I'm going to run this code Ctrl, enter, it will print and execute this method. This is called constructor method. What happens is constructor method execute as soon as the class or the object that we created from the class is executed. So it's surf executed surf.

However, if we create another method for example, here I have created another method. That is def run. Okay, it has a different syntax. Now the in it is keyword in it here is also a keyword. However, here, I use the custom method name that is done. So it is not going to execute itself.

Let's see this. Okay, all right. Create Jerry. Peacock, no matter when I'm going to execute this object. Okay, this gave me an error because Okay. Okay, it requires a name and an age.

I just removed that. And instead of these two just to keep things simple I just this constructor executes okay. So I'm going to run this Okay, this is the constructor meditech executes See? So it executed itself directly when I instantiate the object from the class. Now let's revise this again class attribute. It again to remain same for all the objects of the class.

For example, in this case, it's a bird. In the above case it was the animal that is meant to remain safe. without all the objects objects created from the class, and instance attribute data, according to the instance of the object that is created, it means it is going to be changing. For example, here, the name and age would be changing for each object created from the class. And the constructor method itself executes when the class when the object is executed. So here, let's remove this.

Now let's see this example. Here. What we are doing, we just created a class peacock, the species is bird. And then we created a constructor method with the serve, comma, name, comma age. So we have to define the name and age. These are the parameters required, and we defined it self dot name because to name and self dot age equals to age.

So what the user is required to do when the user creates an object from this class because it gives the name and the So, when these two objects are created, and when you want to run this, we can access this method, I just use the method run to print out. This it will return it will return self dot name that is blue and it will use the method run. So it printed, blue runs happily. If you want to use the name and the heck x is the name and an end age, we can print because name is here. We justified the put the curly braces to use the name that we defined in the object and then the age And it printed exactly the same thing. So this is how we access the instance attribute and the class attribute.

In the next video, we'll be discussing further about these class and objects. I hope you enjoyed the video may have any questions and queries feel free to contact and I would be glad to answer your queries. Thank you

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.