History of Python programmers and history of python programmers
Factorial algorithm code written by various programmers
#-*-Coding: UTF-8 -*-
# New Programmer (recursion)
Def factorial (x ):
If x = 0:
Return 1
Else:
Return x * factorial (x-1)
Print factorial (6)
# Programmers with one year of Python experience
Def Factorial (x ):
Res = 1
For I in xrange (2, x + 1 ):
Res * = I
Return res
Print Factorial (6)
# A lazy Python programmer
Def fact (x ):
Return x> 1 and x * fact (x-1) or 1
Print fact (6)
# More lazy Python programmers
F = lambda x: x and x * f (x-1) or 1
Print f (6)
# Expert Python programmers
Import operator as op
Import functional as f
Fact = lambda x: f. foldl (op. mul, 1, xrange (2, x + 1 ))
Print fact (6)
# Python hacker
Import sys
Def fact (x, acc = 1 ):
If x: return fact (x. _ sub _ (1), acc. mul _ (x ))
Return acc
Sys. stdout. write (str (fact (6) + '\ n ')
# Expert programmers
Imort c_math
Fact = c_math.fact
Print fact (6)
# Programmers with one year of C experience
Def fact (x ):
Result = I = 1;
While (I <= x ):
Result * = I;
I + = 1;
Return result;
Print (fact (6 ))
I am a beginner in Python. I found this article interesting on the Internet, so I want to rewrite it in my blog.
On the one hand, you can improve your Python level, and you can also learn and share with more Python enthusiasts.
I use Python QAQ
Here is a more complete original address: http://python.jobbole.com/15005/