Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Variables, Expression and...
  5. Comments

Comments

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

Loading

Views: 1

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments