Table of Contents
show
Comments are annotations made by the programmer
Uses
- Comments can be used to explain python code
- Comments can be used to make the code more readable
- Comments can be used to prevent execution when testing code
Creating a comment
- Comment starts with a # and python will ignore them
- Comments can be placed at the end of a line and python will ignore them
- Comments does not have to be text to explain the code
Example
>>> print("Learning Python") #this is comment
Learning Python
>>> 5 + 3 # adding two numbers
8
>>> #print("adding two numbers")
... 2 + 5
7
Multi Line comments
- Python does not have support to multi line comments
- To add multiline comment use # for each line
>>> #this is
... #multi line
... #comment
... print("Python")
Python
Views: 1