python - 为什么我的函数中会出现这个 IndentationError?
问题描述
我正在用python开发一个函数。但是我收到此错误 IndentationError: unindent does not match any external indentation level
我应该怎么办?这是我的代码
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_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()
此外,对于缩进,您应该使用制表符,因为它们比空格更一致(不是每个人都知道 4 个空格是正确的缩进),尤其是在像 VSC 这样的成熟文本编辑器中。有些人更喜欢空间,但我个人认为它们只会让事情变得不必要地困难。
推荐阅读
- python - 如何用整行替换特定值Python
- python - 管理依赖 - 管道代码跨越多个文件
- android - 屏幕旋转时Listview不保存项目 - Android Studio
- javascript - 在 Edge 中,对超级方法调用 typeof 会返回“函数”,即使父类中不存在该方法
- java - JPA @repository @Query Can handle a null entity?
- javascript - 如何向 Odoo13 的 POS 订单添加数据
- plsql - 如何随时间保留 PL/SQL 日期参数
- python - 逐行附加 2 个 csv 文件时的内存问题
- c# - Unity3D - 构建失败,因为“[Unity] 错误:资产标记为 HideFlags.DontSave 但包含在构建中:”
- spring-cloud - 假装客户端'readTimeout'与hystrix.execution.isolation.thread.timeoutInMilliseconds的配置之间是否有任何关系