我有一个似乎很简单的问题,我似乎无法补救。
为说明该错误,如果我运行:
a = 'h'
b = 'h'
if b == a:
print('a is b')
else:
print('a is not b')
我明白了:
>>> a = 'h'
>>>
>>> b = 'h'
>>>
>>> if b == a:
...
File "<stdin>", line 2
^
IndentationError: expected an indented block
Python似乎没有解释缩进。
同样,如果我将以下代码作为块运行(没有缩进):
line_one = 'one'
line_two = 'two'
line_three = 'three'
print(line_one)
print(line_two)
print(line_three)
我得到的输出是:
>>> line_one = 'one'
>>>
>>> line_two = 'two'
>>>
>>> line_three = 'three'
>>>
>>> print(line_one)
one
>>>
>>> print(line_two)
two
>>>
>>> print(line_three)
three
当作为一个块运行时,解释器似乎在每行的末尾添加了新行或转义符。我怀疑这会导致缩进错误。
如果有问题,我将在VS Code x64 1.28.1上运行Python 3.7.0
感谢您的宝贵时间。