Different from other programming languages, Python uses whitespace and indentation to establish code block structure. Let’s take a look at a piece of code below to see how whitespace and indentation is used:
First as you see, we defined a function called main. You will learn about the function in the later tutorial, what you need to do is take a look at the structure of program instead of its meaning. The whole block below the main function is the function body which is indented on level. Next after while loop code block is the while loop body. Again it has another level of indentation to indicate it belongs to while loop statement above. Then at the beginning of the new line we call function main which has no identification.
By using indentation and whitespace above, Python code has several advantages:
- You’ll never miss the beginning or ending code like in other languages such as C/C++ .
- Coding style is mostly uniform. If you have to maintain other developers’ code, their code looks pretty as yours.
- Code structure is much more readable and clear.
You also noticed that there are two lines of code which starts with #. Actually they are comments in Python. Comment in Python starts with character #. When interpreter interprets the code, it ignores all the comments. Comment is used for explaining the business logic of code for easier to maintain later.