你好,我想__init__在 Python 的课堂上理解。我理解类是如何工作的,但我无法理解这里的一件事是代码:
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()
为什么以及如何自动Computer("HP ", "i7 ", "16gb ", "1TB ", "256GB")传递参数__init__(self, name, cpu, ram, hdd, ssd)?为什么我们将这个参数写在类括号中而不是像这样分开:
computer1.__init__("HP ", "i7 ", "16gb ", "1TB ", "256GB")
代码如何理解必须将写在 Computer 括号中的参数传递给__init__?
慕工程0101907
PIPIONE
www说
随时随地看视频慕课网APP
相关分类