# Recursion Simply Explained with Code Examples – Python for Beginners

hi everyone today we will talk about recursion now so far weve been using for loops to repeat the same action as many times as wed like but this is not the only way we can also use something called recursive functions now in computer science recursion happens when we call a function within itself meaning the function call is not just outside the function but it is also inside it my favorite example of recursion is matryoshka which is a russian traditional doll that hides smaller and smaller dolls inside it now once we reach the very last doll the one that cant be opened anymore we actually reach something called the base case or the base condition for example if we want to recursively write all the positive even numbers smaller or equal to 8 we will get a list of 8 6 4 and 2 where 2 represents the base case now lets see how it looks like in code we will define a function called even nums which takes in a numeric value of our choice and first we will tackle the base case with if num equals 2 then it means that weve reached the end of the sequence and we will simply return our number however if this is not the case and our number is not equal to two we will need an else clause where we return a call to the even nums function and we pass our number minus 2.

## Shop Learn programming in R: courses

\$ Best Python online courses for 2022

\$ Best laptop for Fortnite

\$ Best laptop for Excel

\$ Best laptop for Solidworks

\$ Best laptop for Roblox

\$ Best computer for crypto mining

\$ Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method