Lesson 24 of 34
Recursion: தன்னைத் தானே அழைக்கும் function
10 min 35 XP
ஒரு function தன்னையே அழைத்தால் அது 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 நிற்காமல் அழைத்துக்கொண்டே இருக்கும்; Python RecursionError தரும்.