What to do with “Unexpected indent” in python?

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

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

17条回答
  •  既然无缘
    2020-11-22 08:11

    Indentation in Python is important and this is just not for code readability, unlike many other programming languages. If there is any white space or tab in your code between consecutive commands, python will give this error as Python is sensitive to this. We are likely to get this error when we do copy and paste of code to any Python. Make sure to identify and remove these spaces using a text editor like Notepad++ or manually remove the whitespace from the line of code where you are getting an error.

    Step1 :Gives error 
    L = [[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
    print(L[2: ])
    
    Step2: L = [[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]print(L[2: ])
    
    Step3: No error after space was removed
    L = [[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
    print(L[2: ])
    OUTPUT: [[7, 8, 9, 10]]
    

    Thanks!

提交回复
热议问题