Code Learning#PYTHON#8216
Back
Indentation Concept
We need to indent instructions that fall under if, for, while def etc. Simple instructions in the main body can not be indented, while instructions within some condition, loop, function etc. must be indented. This is done by giving equal space or tabs on the left side of each instruction within a block.
Source Code
Run Output
Notes
- One must follow PEP-8 style guide for indentation rules
- In python indents can be any number of spaces or tabs, the only requirement is they need to be equal for instructions at equal level. Although as per style guide 4 spaces as indents should be used.
- Spaces and tabs should not be mixed while indentation.
- Instruction in the main body can not be indented.
- If we are making nested conditions or loops (means if within if or while within while etc.) then indents also need to be nested in the similar fashion.
Suggested Filename(s): indent.py, indentation.py, indentation_concepts.py
