Popular Posts

Saturday, August 29, 2020

Python Beginner: Comments

 Hello, Developer!


Today, we will learn the "Comments". Comments are not execute in program but it is really  important to write comments in programs. Because comments make you easily understand codes, features and logic of program.


Comments Declaration and Examples

You can write comments in single line with starting "#" character. (i.e: # This is single line comment)

Also, you can start comments using "#" character in the command line.(i.e: print("This comment explanation line") # This is print out string

For multi-line comment, you can use " ''' " character at the start and end line. 

(i.e: '''

This 

is 

multi 

line 

comments

''')


In the Python programming, "#" character is used for comment officially. So we recommend you to use "#" instead " ''' " multi-line comment command.


Comment also can be used to except codes from running while you're debugging or have code test. If you add "#" character where you want to exclude program running, starting "#" lines won't be run. 


Here, I showed full exercise codes and running result as below.

# This program is cool
# This prints out a string

print("Comments are fun!")
'''
This multi-line comments
won't be run
Because
these lines
are
comments
print("This is comment")
'''

# print("Comment test message)

Can you see the same result? Congratulations! Now you can write comments in the Python program wherever you want.


Thank you for your reading this post and see you on next post, Python developer! 😊


No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...