Stupid way to learn Python (38)

Source: Internet
Author: User

Exercise 38: Reading code

Now find some Python code to read. You need to find the code yourself and learn something from it. What you've learned is enough to make you understand some code, but you may not understand the functionality of the code. What I'm going to teach you in this lesson is: How to use what you've learned to understand someone else's code.

First, print the code you want to understand on paper. Yes, you need to print out, because your eyes and brain are more accustomed to receiving paper-printed content than the screen output. Print up to a few pages at a time.

Then read through the code you print and mark it up, including the following:

    1. Functions and functions of the function.
    2. The initial assignment of each variable.
    3. Each variable that appears more than once in various parts of the program. They may cause trouble for you later.
    4. Any if statement that does not contain else. Are they correct?
    5. Any while loop that may not have an end point.
    6. The last one, any part of the code that you don't understand, is written down.

Next you need to explain the meaning of the code to yourself through annotations. Explain how each function is used, the purpose of each variable, and any other aspect of the content, as long as it helps you to understand the code.

Finally, each part of the code that is difficult to track, line-by-row or function-by-bit tracking variable values. You can print one more copy and write the value of each variable you want to "track" in the blanks.

Once you have a basic understanding of the function of the code, go back to the computer and reread it on the screen to see if you can find a new problem. Then continue to find new code, use the above method to read the understanding, until you no longer need to print paper.

Bonus points Exercise
    1. Study what is "flow chart" and learn to draw.
    2. If you find errors while reading the code, try changing them and sending the changes to the author.
    3. When you're not using paper printing, you can use note symbols # To add notes to your program. Sometimes these notes will be of great help to those who later read the code.

Stupid way to learn Python (38)

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: info-contact@alibabacloud.com 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.