0503 "Learning Programming with Children" reading notes 4

Source: Internet
Author: User
Tags variable scope

1. How to write more and more complex programs? They have to be broken down into smaller parts to organize, so easy to write and easy to understand. So, what are the ways to break the program down into smaller parts? There are mainly 3, the first function, like the code of the building blocks, can be reused, is used to complete a work of the Code block (block), and the other objects (object), you can describe each part of the program as a self-contained unit, its three modules (module), is a separate file that contains the parts of the program.

PS: The above books on the three explanations are not clear, look forward to learning in the process gradually understand the differences.

2.Q: Using loops to let the code run multiple times, do you need to call the function more than once?

A: If you want to print the address at a different location in the program, instead of all at once, the loop will not work, and the function will.

3. Two reasons to use the function: first, once the function is defined, it can be reused by invocation, and the other is that each time the function is run it can behave differently (the latter is implemented by the parameters below); The function can also send back something to you, to let the function return a value, You need to use the keyword return in the function.

4. Function post-parenthesis function: Used to pass parameters (argument). How to understand parameters? It means a piece of information you give to a function. When invoking a function, we enclose the argument in parentheses, in which case the argument is passed into the function.

5. What is the difference between an argument and a formal parameter? It can be said that there is no difference, hard to say there is a difference, you can understand this: when it comes to passing parts (called functions) should be called arguments (argument), and when it comes to the receiving part (inside the function) should be called formal parameters (parameter).

6. For a function, the name inside the function is created only when the function is run, and does not exist even after the function has run or finished running. At the end of the function, the names within all of the functions no longer exist.

7. What is variable scope (scope)? Is the part of the program that uses variables.

8. Difference between local variable and global variable variables? The former is used only within functions that contain its own, which can be used in the main part of a larger program.

9. What happens if you try to change the value of a global variable from within a function? Python creates a new local variable to prevent the function from inadvertently altering global variables. However, there are situations where you really want to change a global variable in a function, what should you do? You can do this with a Python keyword, global.

10. Try the 3rd quiz on the 13th chapter to see how the local variables are forced into global variables, and when the global variables outside the function conflict (that is, they are named the same) the result of the program's operation. The code is as follows:

0503 "Learning Programming with Children" reading notes 4

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.