Python syntax and Comments

Watch video presentation and remember to subscribe to our channel;

Watch now!
In this tutorial we will on python syntaxes and how you can write comments. We will define what is a syntax then look at various syntaxes as applied to python language.

What is a Python Syntax?

Python Syntax -it refers to the set rules which are applied when writing the python program. As we had discussed in our previous tutorial we saw that python program is composed of several lines of codes which are executed one by one. If the rules are violated then it will output syntax error in your program.

Python Identification

Identification is very vital in python language unlike in other programming languages where are used to enhance the readability by the users, as they indicate the spaces left before you write your code line, in python this spaces specifies the block of codes once omitted then the program will bring a syntax error.

Identification can be applied when writing the python variables or just writing the normal printout. Let’s have an example when identification is used and when omitted.

if 8 = 9:
print("The numbers are equal")

#It has identification

if 8 = 9:
print("The numbers are equal")
print("The numbers are not equal")

#It has no identification therefore it brings syntax error

How to insert comments in Python program?

It may come a time when you want to write a comment in between your codes, probably to explain further on a certain concept or what the codes will output, therefore you insert a comment. Comments can be insert for a single line or multiple lines. To insert comment for single line you will use # before the line you wish to appear as a comment while to insert comment for multiple lines you will enclose triple quotes.

Comments are not executed when you run your program either they are just ignored during execution as we have discussed in other languages use of comments, let’s have an example here for better understanding;

#this is a single comment
#it means this text would not be executed
print("We are learning python")

"""All the text which appears in between are comment, 
this format is applied when you are writing comment for multiple lines"""
print("We are learning python")

Thanks for reading through our tutorial, hope you understand python syntax and how to insert comments. As we continue learning python hoping to meet you in our next tutorial.