Python Menu

Comments in Python

In general, Comments are used in a programming language to describe the program or to hide the some part of code from the interpreter.

Comments in Python can be used to explain any program code. It can also be used to hide the code as well.

Comment is not a part of the program, but it enhances the interactivity of the program and makes the program readable.

Python supports two types of comments:

  • Single Line Comments
  • Multi Line Comments

1. Single Line Comments in Python:

In case user wants to specify a single line comment, then comment must start with ‘#’

# This is single line comment

Example: ""
# This is single line comment.  
print("Hello Python") 
Output: $python3
Hello Python

2. Multi Line Comments in Python

Multi lined comment can be given inside triple quotes.The must start at begining of the line.

''' This 
    Multiline comment'''

Example: ""
Multi line comment'''
print("Hello Python")  
Output: $python3
Hello Python

 Python Example Program: Demonstrates usage of Comments in Python

Example: ""
# This example demonstrates usage of Comments

'''	print() used to 
	text on screen '''

print("Welcome to Python")	

#Assign value to variables 

#print sum of two numbers
print("Sum is")
Output: $python3
Welcome to Python
Sum is

Next Topic :IO Operations in Python