Python 如何更正缩进错误:未缩进与任何外部缩进级别不匹配
我得到一个Python 如何更正缩进错误:未缩进与任何外部缩进级别不匹配,python,class,indentation,Python,Class,Indentation,我得到一个缩进错误,如下所示 代码: 错误消息: File "C:/Users/VIRAJ JADHAV/Desktop/College codes in python/data types.py", line 6 def talk(self): ^ IndentationError: unindent does not match any outer indentation level 代码运行良好,但在def talk(sel
缩进错误
,如下所示
代码:
错误消息:
File "C:/Users/VIRAJ JADHAV/Desktop/College codes in python/data types.py", line 6
def talk(self):
^
IndentationError: unindent does not match any outer indentation level
代码运行良好,但在
def talk(self):
行上有额外的空间,这也会影响此函数中代码的缩进
应该是:
class Student:
def __init__(self):
self.name='Viraj'
self.age=17
self.dob=10-1-2003
def talk(self):
print("name-", self.name)
print("age-", self.age)
print("Date of Birth-", self.dob)
s1=Student()
print(s1.name)
s1.talk()
欢迎来到堆栈溢出。请不要大声喊叫。请拿着笔记本阅读。特别是,你的标题应该简洁地概括你的问题,以便其他用户可以快速决定他们是否可以从中提供帮助或学习。我们已经知道你有问题;您正在问答网站上提问。在任何情况下,问题正是错误消息所说的:您的第二个
def
需要额外的空间来匹配第一个def
。它“不匹配任何外部缩进级别”。在询问新文档之前,请记住搜索现有文档、问题等。旁注:self.dob=10-1-2003
setself.dob
至-1994
(10
减1
减2003
)。我想您需要self.dob=“10-1-2003”
,或者使用。
class Student:
def __init__(self):
self.name='Viraj'
self.age=17
self.dob=10-1-2003
def talk(self):
print("name-", self.name)
print("age-", self.age)
print("Date of Birth-", self.dob)
s1=Student()
print(s1.name)
s1.talk()