简体   繁体   English

为什么我的 function 会出现这个 IndentationError?

[英]why do i get this IndentationError in my function?

I was developing a function in python.我在 python 中开发了一个 function。 However I get this error IndentationError: unindent does not match any outer indentation level但是我收到此错误 IndentationError: unindent does not match any external indentation level

what should i do?我应该怎么办? Here is my code这是我的代码

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()

I will use this function again and again我将一次又一次地使用这个 function

customerdetails() is inside the same function it's trying to call. customerdetails()在它试图调用的同一个 function 内。 You cannot call a function from inside itself this way.您不能以这种方式从内部调用 function。 For this code to work customerdetails() must not be indented.要使此代码正常工作, customerdetails()不得缩进。 Here is the correct code:这是正确的代码:

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()

Also, for indenting you should use tabs, as they are much more consistent than spaces (not everyone knows 4 spaces is the correct indentation), especially in an established text editor like VSC.此外,对于缩进,您应该使用制表符,因为它们比空格更一致(不是每个人都知道 4 个空格是正确的缩进),尤其是在像 VSC 这样的成熟文本编辑器中。 Some people prefer spaces, but personally I feel they just make things unnecessarily difficult.有些人更喜欢空间,但我个人认为它们只会让事情变得不必要地困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM