Lesson 24 of 34
Recursion: ತಮ್ಮನ್ನೇ call ಮಾಡುವ Functions
10 min 35 XP
Function ತನ್ನನ್ನೇ call ಮಾಡಿದರೆ ಅದು recursion. ದೊಡ್ಡ ಸಮಸ್ಯೆಯನ್ನು ಅದೇ ರೀತಿಯ ಚಿಕ್ಕ ಸಮಸ್ಯೆಯಾಗಿ ಮಾಡುತ್ತೇವೆ. ನಿಲ್ಲಲು base case ಅಗತ್ಯ.
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.Interview ನೆಚ್ಚಿನದು: n! (factorial). 5! = 5 × 4 × 3 × 2 × 1 = 120, ಅಂದರೆ 5! = 5 × 4!
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.Base case ಇಲ್ಲದಿದ್ದರೆ function ತನ್ನನ್ನೇ ಸದಾ call ಮಾಡುತ್ತಿರುತ್ತದೆ, Python ಅದನ್ನು RecursionError ಮೂಲಕ ನಿಲ್ಲಿಸುತ್ತದೆ.