easy understanding of class:: | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 14

easy understanding 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.

25th Jun 2016, 11:49 PM
Madhav Srikantam
Madhav Srikantam - avatar
4 Réponses
+ 3
is this python or ruby
29th Jan 2017, 7:41 PM
stephen haokip
stephen haokip - avatar
+ 2
Crystal clear. Thanks
29th Jun 2016, 7:29 PM
Dumisani Moyo
Dumisani Moyo - avatar
+ 1
30th Jan 2017, 4:31 AM
Bohdan Paar
It is my understanding that the self.age defines a function [object].age (self bring a placeholder for the object name e.g. Toretto), and that line self.age = age tells the method that the result of this function should be the argument called 'age'. That is, the first of two arguments used to define an object - this comes from the __init__(self, age, gender) which means an object is defined with two arguments called 'age' and 'gender'. I think I am right in assuming that the method names (coming after the dot) don't have to be the same as the argument names, but it is convention that they are.
31st Jan 2017, 6:17 PM
Andrew Rose
Andrew Rose - avatar