comments in python

Python Comment


Topic : Comments in Python



Agenda :

- What are Comment in Python ?
- When to use Comment ?
- How To Write Comment in Python?
- How Does Python interpret Comment ?
- Type Of Comment
    ◇ Single-Line
    ◇ Multi-Line
- Docstring Comment

What are Comment in Python?
- programmer coherent statement
- Describe what a block of code means

When to use Comment?
-Precise and Clear
-Short and Relevant
-Specific to the block of code
-Maintain Language ethics
-Least Redundant

How To Write Comment in Python?
- Comment in Python Start with a “#” Symboll
Program :-
1
2
#Comment in python Start like this
print("Comment in Python start with a #")
Output:-
1
Comment in python start with a #

How Does Python interpret Comment?
- Where a # Symbol is encountered anywhere
- Everything after it will be omitted till the line ends

Type Of Comment
• Single-Line
- Can appear either in an individual line or inline with some other code
- Program:-
1
2
3
4
5
#multiplying two variables
a = 1
b = 2
c = a*b
print(c) # Printing Result
- Output
1
2

• Multi-Line
- Can appear anywhere, but each line should be prefixed by # Character.
- Program:-
1
2
3
4
5
6
#Adding 2 variables
#Printing the result in a new variable
a = 3
b = 2
c = a*b
print(c)
- Output :-
1
6

Docstring Comment
- Documentation string written within quotes that act as comments.
- Program
1
2
3
4
5
6
7
8
9
"""
Docstring are not omited by the interpreter
Using docstring as a comment.
this code divides 2 numbers
"""
x = 8
y = 4
z = x/y
print(z)

- Output
1
2.0






Next Post Previous Post
2 Comments
  • Viji
    Viji Monday, July 19, 2021

    IntelliMindz is the best IT Training Institute in Bangalore with placement, offering 200 and more software courses with 100% Placement Assistance.
    Python Course in Bangalore
    React Course in Bangalore
    Automation Anywhere Training in Bangalore
    Blue Prism Course in Bangalore
    RPA Course in Bangalore

  • Viji
    Viji Monday, July 19, 2021

    IntelliMindz is the best IT Training Institute in Bangalore with placement, offering 200 and more software courses with 100% Placement Assistance.

    UI Path Training in Bangalore
    Clinical SAS Training in Bangalore
    Oracle DBA Training in Bangalore
    IOS Training in Bangalore
    SolidWorks Training in Bangalore

Add Comment
comment url