[英]Python: trying to fix indentation error
class Cylinder(object):
self.pi = 3.14
def __init__(self,height=1,radius=1):
self.height = height
self.radius = radius
def volume(self):
return self.pi * self.radius**2 * self.height
def surface_area(self):
pass
Remove self
from the second line.从第二行中删除
self
。 self
is used only inside class methods to access class instance. self
仅在类方法内部用于访问类实例。 But class attributes declared on class-level apply not to single class instance, but to class itself and all its instances: so they do not require self
.但是在类级别上声明的类属性不适用于单个类实例,而是适用于类本身及其所有实例:因此它们不需要
self
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.