Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

How do I go about computing factorial of an integer in Python?

1 Answer

0 votes
by (106k points)

There are many ways to calculate factorial in Python:-

The first thing you can do is as follows:-

def factorial(n):

  return reduce(lambda x,y:x*y,[1]+range(1,n+1))

Another way would be as follows:-

def factorial(n): 

  if n == 0: 

    return 1 


    return n * factorial(n-1)

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
asked Dec 17, 2020 in Python by laddulakshana (16.4k points)
0 votes
4 answers
0 votes
1 answer

Browse Categories