What to do with “Unexpected indent” in python?

前端 未结 17 2708
天涯浪人
天涯浪人 2020-11-22 07:46

How do I rectify the error \"unexpected indent\" in python?

17条回答
  •  天命终不由人
    2020-11-22 08:23

    This error can also occur when pasting something into the Python interpreter (terminal/console).

    Note that the interpreter interprets an empty line as the end of an expression, so if you paste in something like

    def my_function():
        x = 3
    
        y = 7
    

    the interpreter will interpret the empty line before y = 7 as the end of the expression, i.e. that you're done defining your function, and the next line - y = 7 will have incorrect indentation because it is a new expression.

提交回复
热议问题