Get Started with Python Syntax

Python Indentation: The indentation in Python is very important.

Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. Python uses indentation to indicate a block of code.

Let’s quickly look into few examples how Python indentation works.

Example 1:

From the above Line of code, we are checking Twenty is greater than 10, If statement is true Print Twenty is greater than ten.

Click on Run Button from the menu to execute , or click on Ctrl + Enter / Alt + Enter.

Print statement starts from Letter ‘F, so we don’t have any syntax errors .

Example2 :

In the 6th Line of code, we are checking Ten is greater than 5, If statement is true Print Ten is greater than Five.

Click on Run Button from the menu to execute , or click on Ctrl + Enter / Alt + Enter.

Print statement starts from Letter ‘P’, Here we have Indentation syntax error .

Hope we are clear that The indentation in Python is very important.

How to Use Comments in Python to Make the code More Readable :

1.Comments can be used to explain Python code.
2.Comments can be used to make the code more readable.
3.Comments can be used to prevent execution when testing code.
4.Comments starts with a #, and Python will ignore them.

Hope Now we are Familiar with Python Syntax, we will be exploring on Data types, Variable declarations and operations in the upcoming Posts.