自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

一個(gè)Python程序員的進(jìn)化

開發(fā) 后端
不久前,在互聯(lián)網(wǎng)上出現(xiàn)了一篇有趣的文章,講的是對于同一個(gè)問題,不同層次的Python程序員編出的Python代碼顯示出了不同的風(fēng)格,代碼都很簡單,有趣。下面讓我們一起來看看一個(gè)Python程序員是進(jìn)階的全過程。

不久前,在互聯(lián)網(wǎng)上出現(xiàn)了一篇有趣的文章,講的是對于同一個(gè)問題,不同層次的Python程序員編出的Python代碼顯示出了不同的風(fēng)格,代碼都很簡單,有趣。

編程新手

  1. def factorial(x):  
  2.     if x == 0:  
  3.         return 1  
  4.     else:  
  5.         return x * factorial(x - 1)  
  6. print factorial(6) 

一年編程經(jīng)驗(yàn)(學(xué)Pascal的)

  1. def factorial(x):  
  2.     result = 1 
  3.     i = 2 
  4.     while i <= x:  
  5.         resultresult = result * i  
  6.         ii = i + 1  
  7.     return result  
  8. print factorial(6) 

一年編程經(jīng)驗(yàn)(學(xué)C的)

  1. def fact(x): #{  
  2.     result = i = 1;  
  3.     while (i <= x): #{  
  4.         result *= i;  
  5.         i += 1;  
  6.     #}  
  7.     return result;  
  8. #}  
  9. print(fact(6)) 

一年編程經(jīng)驗(yàn)(讀過 SICP)

  1. @tailcall  
  2. def fact(x, acc=1):  
  3.     if (x > 1): return (fact((x - 1), (acc * x)))  
  4.     else:       return acc  
  5. print(fact(6)) 

一年編程經(jīng)驗(yàn)(Python)

  1. def Factorial(x):  
  2.     res = 1 
  3.     for i in xrange(2, x + 1):  
  4.         res *= i  
  5.     return res  
  6. print Factorial(6) 

懶惰的Python程序員

  1. def fact(x):  
  2.     return x > 1 and x * fact(x - 1) or 1  
  3. print fact(6) 

更懶的Python程序員

  1. f = lambda x: x and x * f(x - 1) or 1  
  2. print f(6) 

Python 專家

  1. fact = lambda x: reduce(int.__mul__, xrange(2, x + 1), 1)  
  2. print fact(6

Python 黑客

  1. import sys  
  2. @tailcall 
  3. def fact(x, acc=1):  
  4.     if x: return fact(x.__sub__(1), acc.__mul__(x))  
  5.     return acc  
  6. sys.stdout.write(str(fact(6)) + '\n'

專家級(jí)程序員

  1. from c_math import fact  
  2. print fact(6

大英帝國程序員

  1. from c_maths import fact  
  2. print fact(6

Web 設(shè)計(jì)人員

  1. def factorial(x):  
  2.     #-------------------------------------------------  
  3.     #--- Code snippet from The Math Vault          ---  
  4.     #--- Calculate factorial (C) Arthur Smith 1999 ---  
  5.     #-------------------------------------------------  
  6.     result = str(1)  
  7.     i = 1 #Thanks Adam  
  8.     while i <= x:  
  9.         #result = result * i  #It's faster to use *=  
  10.         #result = str(result * result + i)  
  11.            #result = int(result *= i) #??????  
  12.         result = str(int(result) * i)  
  13.         #result = int(str(result) * i)  
  14.         i = i + 1 
  15.     return result  
  16. print factorial(6

Unix 程序員

  1. import os  
  2. def fact(x):  
  3.     os.system('factorial ' + str(x))  
  4. fact(6

Windows 程序員

  1. NULL = None 
  2. def CalculateAndPrintFactorialEx(dwNumber,  
  3.                                  hOutputDevice,  
  4.                                  lpLparam,  
  5.                                  lpWparam,  
  6.                                  lpsscSecurity,  
  7.                                  *dwReserved):  
  8.     if lpsscSecurity != NULL:  
  9.         return NULL #Not implemented  
  10.     dwResult = dwCounter = 1 
  11.     while dwCounter <= dwNumber:  
  12.         dwResult *= dwCounter  
  13.         dwCounter += 1 
  14.     hOutputDevice.write(str(dwResult))  
  15.     hOutputDevice.write('\n')  
  16.     return 1 
  17. import sys  
  18. CalculateAndPrintFactorialEx(6, sys.stdout, NULL, NULL, NULL,  
  19.  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) 

企業(yè)級(jí)程序員

  1. def new(cls, *args, **kwargs):  
  2.     return cls(*args, **kwargs)  
  3.    
  4. class Number(object):  
  5.     pass 
  6.    
  7. class IntegralNumber(int, Number):  
  8.     def toInt(self):  
  9.         return new (int, self)  
  10.    
  11. class InternalBase(object):  
  12.     def __init__(self, base):  
  13.         self.base = base.toInt()  
  14.    
  15.     def getBase(self):  
  16.         return new (IntegralNumber, self.base)  
  17.    
  18. class MathematicsSystem(object):  
  19.     def __init__(self, ibase):  
  20.         Abstract  
  21.    
  22.     @classmethod 
  23.     def getInstance(cls, ibase):  
  24.         try:  
  25.             cls.__instance  
  26.         except AttributeError:  
  27.             cls.__instance = new (cls, ibase)  
  28.         return cls.__instance  
  29.    
  30. class StandardMathematicsSystem(MathematicsSystem):  
  31.     def __init__(self, ibase):  
  32.         if ibase.getBase() != new (IntegralNumber, 2):  
  33.             raise NotImplementedError  
  34.         self.base = ibase.getBase()  
  35.    
  36.     def calculateFactorial(self, target):  
  37.         result = new (IntegralNumber, 1)  
  38.         i = new (IntegralNumber, 2)  
  39.         while i <= target:  
  40.             result = result * i  
  41.             i = i + new (IntegralNumber, 1)  
  42.         return result  
  43.    
  44. print StandardMathematicsSystem.getInstance(new (InternalBase,  
  45. new (IntegralNumber, 2))).calculateFactorial(new (IntegralNumber, 6)) 

【編輯推薦】

  1. 年度黑馬Python 自省指南
  2. Ruby趨于人性化 比Python更易閱讀?
  3. 2011年1月編程語言排行榜:Python稱霸2010
  4. 學(xué)習(xí)python處理python編碼
  5. 2011年2月編程語言排行榜:Python繼續(xù)給力超PHP
責(zé)任編輯:陳貽新 來源: 外刊IT評(píng)論
相關(guān)推薦

2020-02-22 21:51:43

程序員Microsoft SServerSQL

2014-01-06 09:33:32

程序員管理

2020-10-05 21:13:37

程序員技能開發(fā)者

2016-12-21 11:35:55

Python程序員

2015-06-08 10:48:39

程序員程序員自白

2020-07-10 09:55:15

程序員技能開發(fā)者

2015-06-16 10:31:36

程序員

2021-07-01 07:43:41

項(xiàng)目程序員代碼

2019-11-07 15:30:00

EmacsIDE

2020-01-06 09:53:29

程序員

2015-08-24 10:07:13

程序員bug

2015-05-13 14:06:03

程序員糟糕的程序員

2010-10-18 11:39:41

程序員

2019-04-22 10:25:52

程序員技術(shù)職場

2012-04-12 14:49:31

程序員

2009-02-12 15:07:57

程序員創(chuàng)業(yè)經(jīng)驗(yàn)

2012-11-28 13:25:27

程序員

2023-12-26 18:47:32

2011-10-31 09:14:35

程序員

2015-04-08 10:57:15

程序員程序員四年經(jīng)歷
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)