Comments are the lines that are skipped during the execution of a program. There are two types of comments available in python:
- Single Line Comment
- Multi Line Comment
Single Line Comment
In Python, a Single line comment starts with the ‘#’ symbol and extends till the end of the line. Comments can start from the beginning of the line and middle of the line, but they should not be a part of the string literal.
Example:
#program to demonstrate explicit type conversion
num1=10 #variable of integer type
num2="20" #variable of string type
result=num1+int(num2) #using explicit conversion print(result)
All the above statements (start with a # sign) mentioned in the code are examples of the single-line comments.
Multi Line Comment
In Python, Multiline comment which starts with ”’ or “”” and ends with ”’ or “”” respectively. Which is mainly used for documentation purposes.
Example:
'''
used for: Demonstrating comments
This is the first way of using multi-line comment
'''
"""
used for: Demonstrating comments
the second way of using multi-line comment
"""
All the above statement (start with ”’ and “”” )mentioned in code are an example of the multiline comment. Such types of comments generally use in class level or method level documentation.
Amazing Thanks for sharing such an amazing article brother. Now, this is called 100% use of the brain. I would like to see more. Moreover, check out my Python Programming