Comments and # Numbers in the Python program

Source: Internet
Author: User

The comments in the Python program are important. They can tell you in natural language what the function of a piece of code is. When you want to temporarily remove a piece of code, you can also temporarily disable the code in the form of annotations. The next exercise will let you learn to annotate:

# A Comment, this was so you can read the your program later.
# Anything after the # are ignored by Python.
Print "I could has code like this." # and the comment after are ignored
# can also use a comment to "disable" or comment out a piece of code:
# print "This won ' t run."
Print "This is run."

From now on, I will write the code in this way. I've been stressing "exactly the same", but you don't have to understand it literally. Your program may appear somewhat different on the screen, but it is important that the text you enter in the text editor is correct. In fact, I can write this program with any editor, and the content is exactly the same.

Of course it is in English, we can write in Chinese, please forgive me to install X

$ python
I could has code like this.
This would run.

Again, I'm not going to put on any more screens.  You should understand that the above content is the literal translation of the output content, and $python ... And the last $ is what you should be concerned about.

Readers can look at the following exercises
1. Figure out the function of the "#" symbol. And remember its name. (Chinese is the pound sign, English is Octothorpe or poundcharacter).
2. Open your file and check back and forth from the rear. Start with the last line, and check back one word at a words backwards.
3. Have you found anything wrong? Some words will be corrected.
4. Read the exercises you have written and pronounce each character. Have you found any more errors? Correct them as well.

answers to frequently asked questions
Are you sure the name of the # symbol is pound character?
I call it Octothorpe, this name is not used in any country, but all people can understand its meaning. Every country feels that their names are the most correct and brightest. It's an arrogant idea for me, and you don't have to worry about the details, it's more important to learn programming.

If # is the meaning of the note, then why #-*-Coding:utf-8-*-can play a role?
Python still does not treat this line as code, which is just a trickery scheme that allows character formatting to be recognized, or a way out of the way. You can also see a similar note in the editor settings.

Why print "Hi # there." The # is not ignored?
The # in this line of code is inside the string, so it is part of the string before the end of the quotation mark, when it is just a normal character, not the meaning of the annotation.

How do I do multiple annotations?
Put a # in front of each line to do it.

Why do I have to read the code backwards?
This avoids letting your brain follow the meaning of each piece of code, which allows you to process each fragment with precision, making it easier to find errors in your code. This is a good error-checking technique.

Reference: "Dumb way to learn Python"
Thank you for reading the Shanghai Shang School Python training article, more content or support, please click on the Shanghai Python Training

Comments and # Numbers in the Python program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.