Factorial of a number in Python

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Basic Python Program, we will find the factorial of a number.

What is factorial of a number?

In Mathematics, Factorial of a non-negative integer is multiplication of all integers smaller than or equal to n.

Example: factorial of 3 will be 3*2*1, that will be 6.

Python Program To Find The Factorial Of A Number

def factorial_num(n): 
     return 1 if (n==1 or n==0) else n * factorial_num(n - 1); 
 num = 3; 
 print("Factorial of",num,"is", 
 factorial_num(num)) 

Output:

Factorial of 3 is 6

Leave a Comment

Your email address will not be published. Required fields are marked *