Python Comments can be used to
- explain Python code.
- make the code more readable.
Comments starts with a #, and Python will ignore them:
Single line comment
Examples
1) #This is a comment
print("Good Morning")
2) print("Welcome") #This is a comment
3) #print("Good Morning")
print("Good Evening")
Multi Line Comments
Python does not really have a syntax for multi line comments.
To add a multiline comment you could insert a # for each line:
Example
#This is a comment
#written in
#more than just one line
print("good evening")
Multiline string(triple quotes)
multiline string (triple quotes) place your comment inside it
Example
"""
This is a comment
written in
more than just one line
"""
print("Hello, Good Morning")
- explain Python code.
- make the code more readable.
Comments starts with a #, and Python will ignore them:
Single line comment
Examples
1) #This is a comment
print("Good Morning")
2) print("Welcome") #This is a comment
3) #print("Good Morning")
print("Good Evening")
Multi Line Comments
Python does not really have a syntax for multi line comments.
To add a multiline comment you could insert a # for each line:
Example
#This is a comment
#written in
#more than just one line
print("good evening")
Multiline string(triple quotes)
multiline string (triple quotes) place your comment inside it
Example
"""
This is a comment
written in
more than just one line
"""
print("Hello, Good Morning")
No comments:
Post a Comment