Comments in Python are used to explain what the code does.
Python has two ways to annotate Python code. One is by using comments to indicate what some part of the code does. Single-line comments begin with the hash character ("#") and are terminated by the end of line. Python is ignoring all text that comes after the # to the end of the line, they are not part of the command. Comments spanning more than one line are achieved by inserting a multi-line string (with """ as the delimiter one each end) that is not used in assignment or otherwise evaluated, but sits in between other statements. They are meant as documentation for anyone reading the code.
Let's show this by using an example
#this is a comment in Python print "Hello World" #This is also a comment in Python """ This is an example of a multiline comment that spans multiple lines ... """
Remember to comment often to explain what the codes does
Recommended Python Training – DataCamp
For Python training, our top recommendation is DataCamp.
Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.
Datacamp has beginner to advanced Python training that programmers of all levels benefit from.
Read more about: