Hello I am trying to understand __init__
in class in Python.I understood how classes work but i could not understand 1 thing
here is code:
class Computer:
def __init__(self, name, cpu, ram, hdd, ssd):
self.name = name
self.cpu = cpu
self.ram = ram
self.hdd = hdd
self.ssd = ssd
def config(self):
print("Configuration of computer is: ", self.name, self.cpu, self.ram, self.hdd, self.ssd )
computer1 = Computer("HP ", "i7 ", "16gb ", "1TB ", "256GB")
computer1.config()
why and how arguments Computer("HP ", "i7 ", "16gb ", "1TB ", "256GB")
are passed to __init__(self, name, cpu, ram, hdd, ssd)
automatically?why we are writing this arguments in class parentheses and not separately like this:
computer1.__init__("HP ", "i7 ", "16gb ", "1TB ", "256GB")
how the code can understand that arguments written in Computer's parentheses have to be passed to __init__
?