EXPLANATION of class : | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 19

EXPLANATION of class :

It's an explanation for those who didn't get the idea of classes,objects,instances,methods. I was having trouble getting the concept behind this. somehow I figured it out and I want to make it clear for all the other people. Here I go :) A Class is a python code,. Whereas a module is a file that contains the python code. A Method is just what it means , so it gives a rule of how the attributes can be used in it. An instance is defining a method with its attributes. Object of a class might be the data of anything. You will give it a name and the data you enter in the brackets is according to the attributes you choose. Here is an example to make it clear. This is the example of a class friends: # THE FAST THE FURIOUS CREW DETAILS class FF: def __init__(self, age, gender): self.age = age self.gender= gender Toretto = FF("48","male") Letty = FF("37", "female") Conner= FF("40","male") Mia= FF("36","female") print (Toretto .age) print(Mia.gender) print(Conner.gender) print(Letty.age) The above example shows us the crew details of FAST AND FURIOUS. EXPLANATION: the class is named as FF, you can name it anything you wish. _init_ is a method , and the way it works is given below it like (self.age = age self.gender= gender) The attributes I chose here are the age and gender of the crew. Toretto,Mia,Letty,Conner are the objects in our class FF. The details of the crew are filled in the brackets according to the method _init_. This is all the input. If you need to access the details of the crew members, just type the member name.the attribute you want like ( Conner.age). Print(Conner.age) That's it , you can enter any data into the class and you don't need to tell what data you are giving each time since they have already been specified in the method place. Create more classes like the and you will understand it clearly. This is as far as I know, please correct me if I'm wrong. Thank you. HAVE A NICE DAY. :)

27th Jun 2016, 1:54 AM
Madhav Srikantam
Madhav Srikantam - avatar
2 Answers
+ 1
letty and conner are objects at run time inside the memory not inside our class they are the 'physical ' representation of our class
8th Jul 2016, 2:00 AM
Kimboo Rasta
Kimboo Rasta - avatar
+ 1
A class put simply is like a blueprint used to create more of the same objects.
23rd Jul 2018, 9:02 PM
Dave David
Dave David - avatar