相关疑难解决方法(0)

我得到一个IndentationError.我如何解决它?

我有一个Python脚本:

if True:
    if False:
        print('foo')
   print('bar')
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行我的脚本时,Python提出了一个IndentationError:

  File "script.py", line 4
    print('bar')
               ^
IndentationError: unindent does not match any outer indentation level
Run Code Online (Sandbox Code Playgroud)

我一直在玩我的程序,我还能够产生其他三个错误:

  • IndentationError: unexpected indent
  • IndentationError: expected an indented block
  • TabError: inconsistent use of tabs and spaces in indentation

这些错误意味着什么?我究竟做错了什么?我该如何修复我的代码?

python error-handling code-formatting exception indentation

38
推荐指数
1
解决办法
2万
查看次数

Python对缩进的制表符和空格的解释

我决定,我学习了一点Python.第一个介绍说它使用缩进来分组语句.虽然最好的习惯显然只使用其中一种,如果我互换它会发生什么?多少个空格将被视为等于一个标签?如果标签和空格混合在一起会不会起作用?

python tabs spaces indentation

32
推荐指数
5
解决办法
4万
查看次数

`If​​`行上的语法错误

我的代码:

#!/usr/bin/env python

def Runaaall(aaa):
  Objects9(1.0, 2.0)

def Objects9(aaa1, aaa2):
  If aaa2 != 0: print aaa1 / aaa2
Run Code Online (Sandbox Code Playgroud)

我收到的错误:

$ python test2.py 
  File "test2.py", line 7
    If aaa2 != 0: print aaa1 / aaa2
          ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会发生这种错误.

python syntax

1
推荐指数
1
解决办法
370
查看次数