Looks like no one added any tags here yet for you.
what is a class
a class is a blueprint or instruction manual for an object
what is an object
an object is a manipulative structure which can be used to simplify tasks in coding by using data attributes (connected to instances) passed into the class (via init function). Then the data attributes can be used in methods
what are instances
instances is kind of like a data type that holds attributes of something (includes different information about one single thing - the instance)
ex. we define the instance item1 into the Item class that holds the parameter of itself as self and then we can pass on more parameters (attributes of the instance) to define in the init method
what are data attributes
data attributes are properties of the instances
ex. item1.price where price is the attribute assigned after the “.” indicator, we can instead put this into the parantheses when putting the instance in the class and define later in init method
what is a method
a method is a function in a class that uses the instances and their properties
what is the method init and what is it used for
the method init is used to define all the attributes of an instance at once before the other methods in a class. outside of the class we pass paramaters in the Item() class when defining the instance into the class, so ex of the parametrs being pushed is
item1 = Item(“Phone”, 100, 5)
where the first paramater before phone is intiially the name of the instance, then the second parameter i guess is “phone” as the name of the item, 100 being the price, and 5 being the quantity
then we can define the attributes in the init function within the class where we assign it like this:
def —init—(self, name, price, quantity):
self.name = name
self.price = price
self.quantity = quantity
this shows that when we define the init function to initialize the attributes we pass the four parameters from the line outside the class into the init function, self being the instance item1 itself, then the name, price, and quantity. then we say self(variable for item1).name = name which is the value passed.