🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!
🖥️ How to use Recursive Function in Python? (Recursion in Python)
In Python, you already know that a Function can call other functions. It is even possible for the function to call itself. These types of construct are termed as Recursive Functions.
A Recursive Function in Python, is a function that calls itself and repeats its behaviour, UNTIL some condition is met - or return a result.
def my_function():
...
my_function()
○ Advantages of Recursion in Python
Recursive functions make the code look clean and elegant.
A complex task can be broken down into simpler sub-problems using recursion.
Sequence generation is easier with recursion than using some nested iteration.
○ Disadvantages of Recursion in Python
Recursive functions are hard to debug.
Sometimes the logic behind recursion is hard to follow through.
Recursive calls are expensive (inefficient) as they take up a lot of memory and time.
○ Example: Recursive Function in Python
In this example, countdown() is a Recursive Function in Python that calls itself, recursively, to countdown. If number is 0 or negative, it prints the word “Stop” then automatically exits this function. Otherwise, it prints number and then calls itself agin, passing "number-1" as the new argument.
def countdown(num):
if num == 0:
print('Stop')
else:
print(num)
countdown(num-1)
countdown(5)
OUTPUT: 5
OUTPUT: 4
OUTPUT: 3
OUTPUT: 2
OUTPUT: 1
OUTPUT: Stop
Let's play this video, stick around and watch until the end of this video! 👍🏻
Digital Academy™ 🎓
***
☞ WATCH NEXT:
○ Data Types in Python - • DATA TYPES in Python (Numbers, String...
○ Operators in Python - • OPERATORS in Python (Arithmetic, Assi...
○ IF Statements in Python - • CONDITIONAL Statements in Python (IF,...
○ FOR Loops in Python - • FOR Loop in Python (Syntax, Break, Co...
📖 Blog: http://digital.academy.free.fr/blog
📖 [FULL Course] HOW TO Learn Python? Python Tutorial for Beginners: • 🐍 Python 101: Learn Python Basics for...
📖 [PLAYLIST] Complete Python Development Course for Beginners: http://digital.academy.free.fr/playli...
🧑🎓 [COURSE] http://digital.academy.free.fr/courses
📘 [BOOK] Python for Absolute Beginners: https://amzn.to/3NvyOWV
🛒 Shopping and Discounts: http://digital.academy.free.fr/store
💌 Weekly Newsletter for Developers: https://www.getrevue.co/profile/digit...
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
✧ http://digital.academy.free.fr/
✧ / digitalacademyy
✧ / digitalacademyfr
✧ / digital_academy_fr
✧ / digitalacademyonline
♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/store
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧ / digital_academy
✧ https://www.buymeacoffee.com/digital_...
***
Sur cette page du site, vous pouvez voir la vidéo en ligne How to use RECURSIVE Function in Python? (Recursion in Python) - Python Tutorial for Beginners durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Digital Academy 23 avril 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 732 fois et il a aimé 19 téléspectateurs. Bon visionnage!