Menu Bar

Horizontal Scrollable Menu

ads

Search This Blog

Python Comment | Creating a Comment | multiline comment | example

 Python comment

Comments will be used to create a case for Python code.


Comments will be used to make the code more legible.


Once the code is tested, comments will not stop execution.


Make a comment


Comments begin with #, and Python may ignore them:


Examples

# This can be a comment

Print ("Hello, World!")


Comments will be placed at the top of a line, and Python may ignore the rest of the line:


Examples

Print ("Hello, World!") # This could be a comment


Comments could not find the text to clarify the code, this may also be used to prevent Python from executing code:


Examples

#print ("Hello, World!")

Print ("Cheers, Met!")


Multi line comments

Python does not have a syntax for multi-line comments.


To add a multi line comment, you can insert a # for each line:


Examples

# This can be a comment # One line has # more written ("Hello, World!"


Or, almost as mean, you would use a multi-line string.


Since Python can ignore string literals that are not assigned to a variable, you will add a multi-line string (triple quotes) to your code, and you will comment within:


Examples


"""
This is a comment

written in

More than just one line

"""       

Print ("Hello, World!")


Python can browse the code until the string is allocated to a variable, ignore it on the other side, and you have created a multi-line comment.

No comments:

ads3