"Python"-recursion, local variables and global variables

Source: Internet
Author: User

1. There must be a clear end condition.

2. Each time a deeper level of recursion is reached, the problem size should be reduced compared to the previous recursion

3. Recursive efficiency is not high, too many recursion levels will cause stack overflow

(In a computer, a function call is implemented through a data structure such as a stack stack, and whenever a function call is entered,

Stack will add a stack frame, whenever the function returns, the station will be reduced a stack of frames, because the size of the stack is not infinite, so,

Too many recursive calls can cause the stack to overflow. )

Local variables and all variables

Scope of local variables:

Scope of all variables:

Global variables are not modified in a subroutine unless the global variable is a string or a number

When the global variable is a different complex type, if all variables are modified in the subroutine, the global variable is all modified.

"Python"-recursion, local variables and global variables

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.