I am currently studying python on my own, but I used everyone's python (fourth edition) and typed it in as below, but they didn't respond according to the reference book.Please tell me where I'm wrong and what I should do. (Python's version is 3.6.5 and I'm practicing using Anaconda's jupyter notebook.)
In(1)class Prism:
def_init_(self, width, height, depth):
self.width = width
self.height=height
self.depth = depth
def content(self):
return self.width*self.height*self.depth
In(2)p1 = Prism(10,20,30)
p1.content()
The reference book says that the return value is 6000, but
--->1p1 = Prism(10,20,30)
2 p1.content()
TypeError: object() takes no parameters
There will be an error.Please let me know.
python
Invalid constructor definition.
class Prism:
def_init__(self, width, height, dept):
self.width = width
self.height=height
self.depth=dept
def content(self):
return self.width, self.height, self.depth
p1 = Prism(10,20,30)
Constructors in python must be defined as def_init__
.definit
is not treated as a constructor, so I went to the constructor of the base class Object to find three patterns, but it was an error.
© 2025 OneMinuteCode. All rights reserved.