How on Factorial
nitinpawar432 at gmail.com
Wed Oct 27 08:42:39 CEST 2010
focus on the AND condition ... return is true only if both conditions are
true so unless the factorial is calculated (second portion of AND statement)
return will not give factorial. the second portion is recursive call to
self as long as x is greater than 1
On Wed, Oct 27, 2010 at 11:55 AM, Geobird <a1chandan at gmail.com> wrote:
> I am a beginner in Python and would ask for a help.
> I was searching for smaller version of code to calculate
> factorial . Found this one
> def fact(x):
> return x > 1 and x * fact(x - 1) or 1
> But I don't really get how ( ....x > 1 and x * fact(x - 1)....)
> works .
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list