Wikipedia:
A class is a cohesive package that consists of a particular kind of metadata. It describes the rules by which objects behave; these objects are referred to as instances of that class. A class has both an interface and a structure. The interface describes how the class and its instances can be interacted with via methods, while the structure describes how the data is partitioned into fields within an instance. A class is the most specific type of an object in relation to a specific layer. A class may also have a representation (metaobject) at runtime, which provides runtime support for manipulating the class-related metadata.
Maybe an example :)
Let's take a look at a car, a car has 4 wheels, 3-5 doors, a certain type of fuel, a brand, engine, bhp, kw,...
So we could say that "car" is just a package name for everything with 4 wheels, 3-5 doors,...
So this could be made with a class
-
class Car:
-
-
doors = 3
-
wheels= 4
-
bhp=115
-
kw=81
-
engine=1900
-
brand="volkswagen"
-
fuel="petrol"
-
-
def __init__(self):
-
#This method is called when a car object is made
-
-
def __init__(self,doors,wheels,bhp,kw,engine,brand,fuel):
-
self.doors = doors
-
self.wheels = wheels
-
self.bhp = bhp
-
self.kw = kw
-
self.engine = engine
-
self.brand = brand
-
self.fuel = fuel
-
-
def implement_more_stuff(self):
-
return None
-
(The code might not be correct but it's about the point right?)
anyway this is how you use it
-
>>>import classexample
-
>>>newcar = classexample.Car()
-
>>>newcar2 = classexample.Car(3,4,200,100,2500,"audi","petrol")
-
>>>newcar2.implement_more_stuff()
-
None
-
>>>newcar.implement_more_stuff()
-
None
-
ok this might seem odd, but what you did was create 2 cars, these cars can have other values in the variables and they can exist next to each other. And yet we only have to import 1 python file.
That is a class in a nutshell