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:
flag=1
#we are using fixed number.
#However you can use input function to input the number from user
input=11
for i in range(2,int(input/2)+1,1):
print(i)
if input%i == 0:
#input number will be divided by 2 to half of the number
flag=0
break #it will exit from the for loop if it is divisible by 2
if flag==1:
print(input, " is a prime number")
else:
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 http://www.facebook.com/freetechtrainer and stay connected.
About The Author
Minhajur Rahman Khan
Professional Experience in Machine Learning with R & Python, Oracle Certified Associate, Google Certified Data Analytics Specialization, IBM Certified Data Science Professional, IBM Certified Data Analyst Professional...
For more details visit: https://www.linkedin.com/in/minhajrk/
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:
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 http://www.facebook.com/freetechtrainer and stay connected.
Related Posts
Replacing Multiple Values in a Column with Pandas in Python
How to Filter Pandas DataFrames in Python
Displaying All Columns and Rows in a DataFrame
About The Author
Minhajur Rahman Khan
Professional Experience in Machine Learning with R & Python, Oracle Certified Associate, Google Certified Data Analytics Specialization, IBM Certified Data Science Professional, IBM Certified Data Analyst Professional... For more details visit: https://www.linkedin.com/in/minhajrk/