Basic Python 25: Recursion in Python | Python
Python Recursion:
----------------------------
What is recursion?
Recursion is the process of defining something in terms of itself.
real exp:
would be to place two parallel mirrors facing each other. Any object in between them would be reflected recursively.
Python Recursive Function:
we 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.
syntax:
def recursion():
-----
----statements
recursion() //call this method
--
--statements
recursion() // calling function
ex:
Factorial of a number
def factorial(x):
"""This is a recursive function
to find the factorial of an integer"""
if x == 1:
return 1
else:
return (x * factorial(x-1))
num = 3
print("The factorial of", num, "is", factorial(num))
how it is run?
--------------
factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call
Our recursion ends when the number reduces to 1. This is called the base condition.
The Python interpreter limits the depths of recursion to help avoid infinite recursions, resulting in stack overflows.
By default, the maximum depth of recursion is 1000. If the limit is crossed, it results in RecursionError.
ex:
def recursor():
recursor()
recursor()
result:
Traceback (most recent call last):
File "string", line 3, in module
File "string", line 2, in a
File "string", line 2, in a
File "string", line 2, in a
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded
Advantages:
- 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:
- 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.
- Recursive functions are hard to debug.
___________________ API Automation __________________
➡️ Rest Assured Using Java → https://youtube.com/playlist?list=PLQKDzuA2cCjrxlZkE8e_NOeQFJQXRHp0n
➡️ Karate Framework using Maven → https://youtube.com/playlist?list=PLQKDzuA2cCjoWKMw8bpnOlr70PNSVdkf6
______________ Programing Language _____________________
➡️ Basic Python → https://youtube.com/playlist?list=PLQKDzuA2cCjp-gnUFFPvXcMllAlfVPph5
➡️ Core Java → https://youtube.com/playlist?list=PLQKDzuA2cCjod85qsWBGR-25onbE1GH_i
____________ Performances Testing ____________________
➡️ JMeter Beginner → https://youtube.com/playlist?list=PLQKDzuA2cCjrukNp3JNCTnKi89C9CiFz8
➡️ Locust Beginner → https://youtube.com/playlist?list=PLQKDzuA2cCjptRRRUWyLZoaeVuoctG35L
____________ Git and GitHub ______________________________
➡️ Git and GitHub Beginner → https://youtube.com/playlist?list=PLQKDzuA2cCjrsvfgzsVajJVqj7rck7X2q
______________Manual Testing _____________________
➡️ Manual Testing → https://youtube.com/playlist?list=PLQKDzuA2cCjovVbXzK8QiVeZamz-lLW0-
_______________Automation Testing ___________________
➡️ Selenium Cucumber Framework using Java → https://youtube.com/playlist?list=PLQKDzuA2cCjpsMVO0Cj_JIDURpJSzVcmn
➡️ Robot Framework with Python → https://youtube.com/playlist?list=PLQKDzuA2cCjrVs8t8_b4LTguHA1XGTZI_
➡️ Beginner Karate Framework using Intellij → https://youtube.com/playlist?list=PLQKDzuA2cCjqUiNSoEtGJSAuDYvleZcpQ
➡️ Karate Framework with Gradle using eclipse → https://youtube.com/playlist?list=PLQKDzuA2cCjo_VayskAv-1qnUg1b2mjWi
➡️ Basic Selenium WebDriver using Java → https://youtube.com/playlist?list=PLQKDzuA2cCjpEL8xZFg6I1TOcerxKh0nX
➡️ TestNG Framework → https://youtube.com/playlist?list=PLQKDzuA2cCjoKVdgCDCuCnUMFv-9jZ2cr
➡️ Robot Framework with RIDE → https://youtube.com/playlist?list=PLQKDzuA2cCjqmT4GambzrUjtLfEkXmMzw
_________________ Beginner Jenkins _____________________
➡️ Beginner Jenkins → https://youtube.com/playlist?list=PLQKDzuA2cCjrwNyMgYffggbTMoNrtwpGk
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Basic Python 25: Recursion in Python | Python», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.