Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.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/8/python-3.x/19.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_Python 3.x_Visual Studio Code - Fatal编程技术网

Python 为什么我的函数中会出现这个缩进错误?

Python 为什么我的函数中会出现这个缩进错误?,python,python-3.x,visual-studio-code,Python,Python 3.x,Visual Studio Code,我在用python开发一个函数。但是,我得到了这个错误IndentationError:unindent与任何外部缩进级别都不匹配 我该怎么办?这是我的密码 def customerdetails(): Firs_tname = input("Enter your First name:") Last_name = input("Enter your last name:") Age = input("Age:

我在用python开发一个函数。但是,我得到了这个错误IndentationError:unindent与任何外部缩进级别都不匹配

我该怎么办?这是我的密码

def customerdetails():
      Firs_tname = input("Enter your First name:")
      Last_name = input("Enter your last name:")
      Age = input("Age:")
      Address =input("Enter your address:")
      Postcode = input("Enter your Postcode:")
      Email = input("Email:")
      Phone = int(input("Phone Number:"))
    customerdetails()

我将反复使用此函数

customerdetails()
位于它试图调用的同一函数中。不能用这种方式从函数本身内部调用函数。要使此代码正常工作,不得缩进
customerdetails()
。以下是正确的代码:

def customerdetails():
Firs\u tname=input(“输入您的名字:”)
姓氏=输入(“输入您的姓氏:”)
年龄=输入(“年龄:”)
地址=输入(“输入您的地址:”)
邮政编码=输入(“输入您的邮政编码:”)
电子邮件=输入(“电子邮件:”)
Phone=int(输入(“电话号码:”)
客户详细信息()

此外,对于缩进,您应该使用制表符,因为制表符比空格更一致(不是每个人都知道4个空格是正确的缩进),特别是在VSC等已建立的文本编辑器中。有些人喜欢空格,但我个人觉得它们只是让事情变得不必要的困难。

你可以在代码中看到:行
customerdetails()
有不同的缩进。根据,您应该始终使用4个空格来缩进。否。空格应用于缩进。如果你使用空格,它们的数量是一致的(最好是四个),你很可能会在缩进中弄糟,而且使用起来比标签慢得多。不过,这也是一个偏好问题。“你不能从函数本身内部调用它”???你听说过递归吗?这可能不适用于这里,但是这个陈述是错误的。@Shidouuu-well。这是一个偏好的问题,而PEP8——官员。当然,你可以自由使用标签,但你不应该把这种不好的做法称为“更好”。主要原因是,在编辑器和OS-es之间,tab实际上并不一致。PEP8创建于2001年。现代文本编辑器在与选项卡交换代码时没有问题。