In this lecture we will learn:
- Recursion in Python
- Find the factorial of a number by using the recursion
- How the function inside a function works?
- Logic for finding the factorial using recursion
#1
- Recursion is a function calling itself.
1. Create a variable to store the factorial of a number.
2. Assign the variable by the fact() function and pass a number in it as an argument.
3. Print the value of the variable to get the result.
4. Define the function say fact() above the main code.
- A function can be defined by using the keyword def.
def fact(n):
5. Call the same function inside the fact() function by applying the correct logic and return its value.
return n*fact(n-1)
6. Apply the condition for the factorial of a 0 as it is always 1.
- In this way, the factorial of a number will be printed by using the recursion.
Python Tutorial to learn Python programming with examples
Complete Python Tutorial for Beginners Playlist : • #1 Python Tutorial for...
Python Tutorial in Hindi : • #1 Python Tutorial | I...
Github :- github.com/nav...
Check out our courses:
Spring and Microservices Weekend Live Batch : bit.ly/spring-...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-sp...
Java and Spring Framework For beginners with Spring Boot : - bit.ly/3LDMj8D
Java Tutorial for Beginners (2023) :- bit.ly/3yARVbN
Editing Monitors :
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Check out our website: www.telusko.com
Follow Telusko on Twitter: / navinreddy20
Follow on Facebook:
Telusko : / teluskolearn. .
Navin Reddy : / navintelusko
Follow Navin Reddy on Instagram: / navinreddy20
Subscribe to our other channel:
Navin Reddy : www.youtube.co....
Telusko Hindi :
www.youtube.co....
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
www.telusko.com...
Негізгі бет #41 Python Tutorial for Beginners | Factorial using Recursion
Пікірлер: 1 М.