+ 1
What are classes and objects?
Hello everyone! I’m learning Python for a few months, and I know basically everything except Classes and Objects. What are they? Are they connected to each other? Every explanation will be welcome! Thanks.
4 ответов
+ 3
Classes:
class is the blue print of our object.basically class tell you how is our object.In class you add some attributes.these attributes belong to object.means object should be all attributes of class.by defining class you can do anything with your object which is defined in class.
object:-
we create object to use our class.
e.g=
class Car:
def__init__(self,speed,colour)
self.s=speed
self.c=colour
y=Car(250,red)
print(y.s) # output=250
-----------------------
where y is object.In class self means object name.
+ 2
Consider an animal as a class and type of animal like dog or cat can be considered as an object which has properties like size, color, strength, height etc.
Basically classes are for grouping the similar things or requirements which are related to functionality of that class.
These functionalities can be implemented using objects.
Hope this is helpful
0
thank you very much you two