+ 2
What is indentation?
I can't understand it
2 Respostas
+ 9
Indentation is keeping the code blocks indented, that is aligned straight to the same vertical line - with the same number of spaces, counting from the left. For example, in Python this is how you make logical chunks of code - loop or if statement bodies.
if a == 1:
print("Indentation")
print(a)
It the example above, the if statement's body is indented - each line is preceded with four spaces (which is the conventional rule). For nested blocks, you'd have to indent again with the same number, eight spaces overall:
if a == 2:
print("Indentation")
if b == 3:
print("Nested indentation")
It is always a good practice to keep the indentation step fixed (4 spaces, then 8, then 12...) It is a necessity in Python and just keeps the code easily readable - in other languages.
+ 2
thanks 👍