(record) Python article: six _ Function 2

Source: Internet
Author: User

#递归函数

#函数内部, a function can call itself, and this function is a recursive function.

def num (x): #第一步 return Num_a (n,1) #第二部def num_a (A, A, b): #与第二部对应, if the num_a at this time does not correspond to the function defined in the previous step, the code will error.        If A==1: # (Last Judgment) because a==3, so a==1 not set up, until the a==1 to return B, the loop will end. Return b return Num_a (A-1,A*B) #此时循环结束, but the loop in the judgment is not over.


#x等于3时

#num_a (3,1)

#num_a (2,3)

#num_a (1,6)

#返回num_a (a-1,a*b) value with the above for Num_a (A, b), a is continuously reduced by 1, whereas the a*b of the definition expression is multiplied until a==1, the judgment is established, and return returns to the end.

#所以答案为num_a (1,6), a==1,b==6

#此递归函数也和循环是等价的, but he does not rely on the circular statement, but itself constantly called functions, so there will be a stack overflow problem.



Learn from Liu Junfeng's official website!



PS: I python is not plagiarism, but to learn the article >>> write is I study notes, record down convenient I later reference.

This article is from the "Twist Blog" blog, please be sure to keep this source http://mahua.blog.51cto.com/11572858/1969786

(record) Python article: six _ Function 2

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.