Python Program for factorial of a number
Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720.

Recursive :
# Python 3 program to find # factorial of given number def factorial(n): # single line to find factorial return 1 if (n==1 or n==0) else n * factorial(n - 1); # Driver Code num = 5; print("Factorial of",num,"is", factorial(num)) # This code is contributed by Smitha Dinesh Semwal |
chevron_right
filter_none
Iterative:
# Python 3 program to find # factorial of given number def factorial(n): # single line to find factorial return 1 if (n==1 or n==0) else n * factorial(n - 1); # Driver Code num = 5; print("Factorial of",num,"is", factorial(num)) # This code is contributed by Smitha Dinesh Semwal |
chevron_right
filter_none
One line Solution (Using Ternary operator):
# Python 3 program to find # factorial of given number def factorial(n): # single line to find factorial return 1 if (n==1 or n==0) else n * factorial(n - 1) # Driver Code num = 5print ("Factorial of",num,"is", factorial(num)) # This code is contributed # by Smitha Dinesh Semwal. |
chevron_right
filter_none
Please refer complete article on Program for factorial of a number for more details!
Recommended Posts:
- Python Program to Count trailing zeroes in factorial of a number
- Program for factorial of a number
- C Program for factorial of a number
- Java Program for factorial of a number
- Python Program for Efficient program to print all prime factors of a given number
- Python Program to Find the Number Occurring Odd Number of Times
- Find the last digit when factorial of A divides factorial of B
- Python Program for How to check if a given number is Fibonacci number?
- Factorial of a large number
- Sum of divisors of factorial of a number
- First digit in factorial of a number
- Calculate MDAS Factorial of given number
- Smallest number with at least n digits in factorial
- One line function for factorial of a number
- Smallest number S such that N is a factor of S factorial or S!


