What are comments and statements in Python?
Comments are used for explaining a code. It makes the code more readable and enables the on-looker to have an idea about the program and functionality of particular lines of code. Python ignores the text mentioned in the program. Comments are written in two ways:
→ Single line comments:
This type of comment is written by putting # at the beginning of the statement. Python ignores everything written after #. Example,
print("I love vs.eyeandcontacts.com!")
→ Multi line comments:
This type of comment is written by adding # to each line of comment or by enclosing the comments in triple quotes (can be done with single or double quotes).
Example,
Input:
#which will not be implemented
#by Python
print("I love vs.eyeandcontacts.com!")
Input:
This is
a
comment
'''
print("Hello!")
"""
This is
a multi line
comment
"""
print("I love this site!")
I love this site!
In the above examples, the comments are ignored by Python. Do note that the command or any function written in the comments will be ignored. Example,
Input:
#print("Hello!")
print("I love vs.eyeandcontacts.com!")
Statements in Python are any instructions that a Python interpreter can execute.
No comments:
Post a Comment