How on Factorial
Nitin Pawar
nitinpawar432 at gmail.com
Wed Oct 27 02:42:39 EDT 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 .
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101027/8604fae1/attachment-0001.html>
More information about the Python-list
mailing list