Unindent Code in Python

Unindent Code in Python

Manav Narula Jan-22, 2022 Nov-09, 2021 Python Python Unindent

In Python, we use indentation to determine blocks of code. Unlike other languages, we do not use curly braces or parentheses to specify a block of code.

We can adequately indent our code using spaces or tabs. We should note that both are considered different in Python. So one should be careful and use only one type of indentation in the whole code.

We will now discuss how to unindent a code in Python.

The most straightforward way to achieve this is by simply backspacing the spaces that we wish to unindent. However, this is not a convenient way to achieve this if we have a massive code block.

In such cases, we have shortcut keys and options in different IDEs. For someone working with Jupyter Notebook, we can unindent a selected block of code using the combination of Shift and Tab keys. We can use the same combination for Eclipse, PyCharm, and Visual Studio as well.

In Python IDLE/Spyder, we use the Ctrl + [ to unindent a code block.

Author: Manav Narula
Manav Narula avatar Manav Narula avatar

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.