在运行时,我在init函数中收到一个缩进错误,我试图通过移动错误行来解决它来解决它。
class Category:
"""
Creates category class, possible child class of products
Parameters
name : str, default blank
Desired name of category
category_type : str, default blank
type of category
model : int , default 0
model of category in years
"""
#Declaring __init__()Function
def __init__(self,name="",category_type="",model=0):
"""
Constructs all the necessary attributes for the category object.
Parameters
----------
name : str
name of the category
category_type : str
category type of the category
model : int
year of the category
"""
self.name = name
self.category_type = category_type
self.model = model
print (name,"Created!") # Run when init is finished.
#Declaring print_status()Function
def print_status(self):
print("Category :{0}\n category type :{1}\n Model :{2}".format(self.name,self.category_type,self.model))
p1 = Category("Iphone","Technology",2020)
p1.print_status()
错误消息:文件“”,第26行self.name =名称^ IndentationError:unindent与任何外部缩进级别都不匹配
是Docstring!
def __init__(self,name="",category_type="",model=0):
"""
Constructs all the necessary attributes for the category object.
Parameters
----------
name : str
name of the category
category_type : str
category type of the category
model : int
year of the category
"""
self.name = name
self.category_type = category_type
self.model = model
print (name,"Created!") # Run when init is finished.
#Declaring print_status()Function
def print_status(self):
print("Category :{0}\n category type :{1}\n Model :{2}".format(self.name,self.category_type,self.model))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句