What are comments and statements in Python? | Python Basics


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,

Input:
#This comment will be ignored by Python
print("I love vs.eyeandcontacts.com!")
Output:
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:
#This is a comment
#which will not be implemented
#by Python
print("I love vs.eyeandcontacts.com!")
Output:
I love vs.eyeandcontacts.com!

Input:
'''
This is
a
comment
'''
print("Hello!")
"""
This is
a multi line
comment
"""
print("I love this site!")
Output:
Hello!
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:
#This is a function:
#print("Hello!")
print("I love vs.eyeandcontacts.com!")
Output:
I love vs.eyeandcontacts.com!

Statements in Python are any instructions that a Python interpreter can execute.

No comments:

Post a Comment

Also read!

Click on any of the below text for additional links:

Class 6

→ Class 6 Computer Kips Solutions
→ Class 6 Gul Mohar English Solutions
→ Class 6 Map Pointing Solutions
→ Class 6 NCERT Civics Solutions
→ Class 6 NCERT Geography Solutions
→ Class 6 NCERT History Solutions
→ Class 6 NCERT Maths Solutions
→ Class 6 NCERT Science Solutions

Class 7

→ Class 7 Computer Kips Solutions
→ Class 7 Gul Mohar English Solutions
→ English Grammar Class 7
→ English Writing Skills Class 7
→ Class 7 Map Pointing Solutions
→ Class 7 NCERT Civics Solutions
→ Class 7 NCERT Civics Notes
→ Class 7 NCERT Civics Extra Questions
→ Class 7 NCERT Geography Solutions
→ Class 7 NCERT Geography Notes
→ Class 7 NCERT Geography Extra Questions
→ Class 7 NCERT History Solutions
→ Class 7 NCERT History Notes
→ Class 7 NCERT History Extra Questions
→ Class 7 NCERT Maths Solutions
→ Class 7 NCERT Science Solutions
→ Class 7 NCERT Science Notes
→ Class 7 NCERT Science Extra Questions

Class 8

→ Class 8 Kips Artificial Intelligence Solutions
→ Class 8 Gul Mohar English Solutions
→ English Grammar Class 8
→ English Writing Skills Class 8
→ Class 8 Map Pointing Solutions
→ Class 8 NCERT Civics Solutions
→ Class 8 NCERT Civics Notes
→ Class 8 NCERT Civics Extra Questions
→ Class 8 NCERT Geography Solutions
→ Class 8 NCERT Geography Notes
→ Class 8 NCERT Geography Extra Questions
→ Class 8 NCERT History Solutions
→ Class 8 NCERT History Notes
→ Class 8 NCERT History Extra Questions
→ Class 8 NCERT Maths Solutions
→ Class 8 NCERT Science Solutions
→ Class 8 NCERT Science Notes
→ Class 8 NCERT Science Extra Questions
→ Class 8 NCERT Science Exemplar
→ Class 8 NCERT Science MCQs

Class 9

→ Class 9 Kips Artificial Intelligence Solutions
→ Class 9 Map Pointing Solutions
→ Class 9 NCERT Civics Solutions
→ Class 9 NCERT Geography Solutions
→ Class 9 NCERT History Solutions
→ Class 9 NCERT Maths Solutions
→ Class 9 NCERT Science Solutions

Class 10

→ Class 10 Kips Artificial Intelligence Solutions
→ Class 10 NCERT English Solutions
→ Class 10 Map Pointing Solutions
→ Class 10 NCERT Civics Solutions
→ Class 10 NCERT Civics Notes
→ Class 10 NCERT Civics Extra Questions
→ Class 10 NCERT Geography Solutions
→ Class 10 NCERT Geography Notes
→ Class 10 NCERT Geography Extra Questions
→ Class 10 NCERT History Solutions
→ Class 10 NCERT History Notes
→ Class 10 NCERT History Extra Questions
→ Class 10 NCERT Maths Solutions
→ Class 10 NCERT Science Solutions
→ Class 10 NCERT Science Notes
→ Class 10 NCERT Science Extra Questions

Computer Languages

→ Python Basics

Extra Activities

→ Extra Activities

Extra Knowledge

→ Extra Information
→ General Knowledge
→ Historical Places in India
→ Latest technology
→ Physical Sciences
→ Facts

• Mathematics quick links
→ Mathematical Terms
→ Maths Tricks

Home Top