How to use comments features in Python

Sometimes you may need to write some comments in your python code which you don’t want to be executed. Like any other programming languages Python has this commenting facility. Generally programmers want do three things: a) note or explanation about the code, b) To make the code to be more readable, c) prevent to execute the code.

In Python, # symbol is used in the starting of the code to ignore them. Let’s see the an examples of commenting Python Code:

#we are using fixed number.
#However you can use input function to input the number from user
for i in range(2,int(input/2)+1,1):
    if input%i == 0: 
    #input number will be divided by 2 to half of the number
        break #it will exit from the for loop if it is divisible by 2
if flag==1:
    print(input, " is a prime number")
    print(input, " is not a prime number")

In this tutorial, I have shown how to use comment feature in Python. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page and stay connected.

Add a Comment