Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何更正缩进错误:未缩进与任何外部缩进级别不匹配_Python_Class_Indentation - Fatal编程技术网

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
set
self.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()