+ 2

What is indentation?

I can't understand it

3rd Jul 2017, 3:22 PM
Jay Chheda
Jay Chheda - avatar
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.
3rd Jul 2017, 3:42 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
thanks 👍
3rd Jul 2017, 4:02 PM
Jay Chheda
Jay Chheda - avatar