Python:简单代码中的缩进错误

时间:2015-10-20 15:27:42

标签: python

我输入以下代码

def root():
    x = int(raw_input("Enter a number:\n"))
    y = int(raw_input("Enter the power which you want:\n"))
    return x^y
print "Hey, we are learning python!"
print "Let's learn about functions!"
print "The result is:", root()

我收到以下错误:

y = int(raw_input("Enter the power you want\n:"))
^
Indentation Error: unexpected indent

1 个答案:

答案 0 :(得分:0)

您应该在整个代码中使用相同的缩进。 如果从4个空格开始,到处使用4个空格。 如果您从制表符开始,请继续使用标签等。

因此,在复制具有不同缩进的文件的代码时也要小心。

某些文本编辑器(即Sublime)或IDE可以将整个文件转换为相同的缩进以避免此类错误。