Python3 recursive function, python3 Recursive Function

Source: Internet
Author: User

Python3 recursive function, python3 Recursive Function

 

1 # def fat (n): 2 # result = 1 3 # for I in range (2, n + 1 ): 4 # result = result * I 5 # return result 6 # print (fat (5) 7 #8 #9 # def digui (x ): 10 # if x = # return 112 # return x * digui (x-1) 13 # print (digui (5 )) 14 #15 # ''' 16 # recursive Summary: 17 #1. internally, it calls itself 18 #2. there is an end condition 19 #3. but any recursion that can be written can be done in a loop of 20 #4. low recursion Efficiency 21 # ''' 22 #23 #24 ## recursive version Fibonacci Series 25 #0 1 1 2 3 5 8 13 21... 26 # def feibonaqidigui (a): 27 # if a = 0 or a = # return a29 # return feibonaqidigui (A-1) + feibonaqidigui (A-2) 30 # print (feibonaqidigui (8) 31 #32 # ''' 33 # recursive features: 34 #1. there must be a clear ending condition 35 #2. each time you enter a deeper layer of recursion, the problem scale is reduced by 36 #3 compared to the previous recursion. inefficient, too many recursive layers will cause stack overflow 37 #'''

 

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.