【问题标题】:Python: getting an error for function, Unindented errorPython:获取函数错误,未缩进错误
【发布时间】:2013-10-12 21:35:22
【问题描述】:

我是 Python 新手,我正在尝试将我的字符串从 'abc' 更改为 'def' 简而言之,我不断收到,"unindented does not match any other indentation level." 因此,这意味着我的函数有什么问题?

def changes(x):

   if 'a' in sent:
       x=sent.replace('a','d')

    if 'b' in x:
        y=x.replace('b','e')

    if 'c' in y:
        z=y.replace('c','f')
    print(z)

sent=print(input('Enter a sentence:'))

changes(x)

【问题讨论】:

  • 这是一个缩进问题,第一个 if 块似乎比其他块少一个空间。

标签: python indentation python-3.1


【解决方案1】:

只需检查您的缩进即可。你不能像用其他语言那样在任何地方写任何东西。

阅读此short guide.

【讨论】:

    【解决方案2】:

    我曾经并且仍然有很多这样的错误。我发现真正有用的是打开,这样我就可以看到隐形或空白。当从网络上复制代码片段时,或者在使用空格键和制表符之间切换来创建缩进时,这可能会产生缩进问题

    检查 if 'a' in sent 和下面的行。似乎使用的空格比后续情况少。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多