python程序员发展-Python程序员的进化史
不久前,在互联网上出现了一篇有趣的文章,讲的是对于同一个问题,不同层次的程序员编出的 Python 代码显示出了不同的风格,代码都很简单,有趣。
编程新手
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
一年编程经验(学 Pascal 的)
def factorial(x):
result = 1
i = 2
while i <= x:
result = result * i
i = i + 1
return result
print factorial(6)
一年编程经验(学 C 的)
def fact(x): #{
result = i = 1;
while (i <= x): #{
result *= i;
i += 1;
#}
return result;
#}
print(fact(6))
一年编程经验(读过 SICP)
@tailcall
def fact(x, acc=1):
if (x > 1): return (fact((x - 1), (acc * x)))
else: return acc
print(fact(6))
一年编程经验(Python)
def Factorial(x):
res = 1
for i in xrange(2, x + 1):
res *= i
return res
print Factorial(6)
懒惰的 Python 程序员
def fact(x):
return x > 1 and x * fact(x - 1) or 1
print fact(6)
更懒的 Python 程序员
f = lambda x: x and x * f(x - 1) or 1
print f(6)
Python 专家
import operator as op
import functional as f
fact = lambda x: f.foldl(op.mul, 1, xrange(2, x + 1))
print fact(6)
Python 黑客
import sys
@tailcall
def fact(x, acc=1):
if x: return fact(x.__sub__(1), acc.__mul__(x))
return acc
sys.stdout.write(str(fact(6)) + ' ')
专家级程序员
import c_math
fact = c_math.fact
print fact(6)
大英帝国程序员
import c_maths
fact = c_maths.fact
print fact(6)
Web 设计人员
def factorial(x):
#-------------------------------------------------
#--- 这段代码是从 Math Vault 那弄过来滴---
#--- 计算阶乘 (C)亚瑟·史密斯 1999年---
#-------------------------------------------------
result = str(1)
i = 1 #谢谢亚当
while i <= x:
#result = result * i #It's faster to use *=
#result = str(result * result + i)
#result = int(result *= i) #??????
result str(int(result) * i)
#result = int(str(result) * i)
i = i + 1
return result
print factorial(6)
Unix 程序员
import os
def fact(x):
os.system('factorial ' + str(x))
fact(6)
Windows 程序员
NULL = None
def CalculateAndPrintFactorialEx(dwNumber,
hOutputDevice,
lpLparam,
lpWparam,
lpsscSecurity,
*dwReserved):
if lpsscSecurity != NULL:
return NULL #Not implemented
dwResult = dwCounter = 1
while dwCounter <= dwNumber:
dwResult *= dwCounter
dwCounter += 1
hOutputDevice.write(str(dwResult))
hOutputDevice.write(' ')
return 1
import sys
CalculateAndPrintFactorialEx(6, sys.stdout, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
企业级程序员
def new(cls, *args, **kwargs):
return cls(*args, **kwargs)
class Number(object):
pass
class IntegralNumber(int, Number):
def toInt(self):
return new (int, self)
class InternalBase(object):
def __init__(self, base):
self.base = base.toInt()
def getBase(self):
return new (IntegralNumber, self.base)
class MathematicsSystem(object):
def __init__(self, ibase):
Abstract
@classmethod
def getInstance(cls, ibase):
try:
cls.__instance
except AttributeError:
cls.__instance = new (cls, ibase)
return cls.__instance
class StandardMathematicsSystem(MathematicsSystem):
def __init__(self, ibase):
if ibase.getBase() != new (IntegralNumber, 2):
raise NotImplementedError
self.base = ibase.getBase()
def calculateFactorial(self, target):
result = new (IntegralNumber, 1)
i = new (IntegralNumber, 2)
while i <= target:
result = result * i
i = i + new (IntegralNumber, 1)
return result
print StandardMathematicsSystem.getInstance(new (InternalBase,
new (IntegralNumber, 2))).calculateFactorial(new (IntegralNumber, 6))
python程序员发展-Python程序员的进化史相关推荐
- 助力小程序生态发展 “小程序生态孵化社区”成立
今年以来,小程序进入爆发之年,各类小程序平台的出现给急速发展的小程序生态带来了碎片化等问题和挑战. 2019年10月10日,由阿里巴巴标准化部主导发起的小程序生态孵化社区在北京正式成立.来自各行各业的 ...
- python语言能够整合各类程序代码-python语言概述
python语言的发展 python语言诞生于1990年,由Guide van Rossum设计并领导开发. python语言是开源项目的优秀代表,其解释器的全部代码都是开源的. 编写Hello程序 ...
- python程序员发展-2018年,程序员对Python有着这些期待!
[IT168 评论]自1991年首次发布以来,Python的普及程度已经大大提高,现在已经跻身在世界上最流行的编程语言之列,战胜了那些声明速度太慢或无法扩展的语言. 事实上,最近PayPal,Inst ...
- 30岁自学python找工作-程序员自学Python开发,20到30岁几乎决定了你的未来!
原标题:程序员自学Python开发,20到30岁几乎决定了你的未来! 之前程序员界流行一句话:人生苦短,请用Python. 随着Python成为网红语言之后,不少程序员想多学这一门语言好傍身. 甚至有 ...
- python 线程池_老程序员的经验分享:Python 从业十年是种什么体验?
出于某些原因,想记录一下我过去数年使用 Python 的经验和一些感悟.毕竟算是一门把我带入互联网行业的语言,而我近期已经几乎不再写 Py 代码, 做一个记录,也许会对他人起到些微的帮助,也算是纪念与 ...
- python好学吗 老程序员-学习python,难道是为了当一名苦逼的程序员吗?
最近在和朋友聊天的时候,朋友问了我这样一个问题,问我:你报培训班学习python有用吗?听说程序员虽然工资高,但是工作强度很大,天天加班而且还会遇到中年危机,不像律师,会计这种越老越挣钱.当我听完后, ...
- python最难的地方_全国 41611 个景点,程序员用 Python 告诉你哪些地方最值得一游!...
原标题:全国 41611 个景点,程序员用 Python 告诉你哪些地方最值得一游! 经常听到别人说"世界那么大,我想去看看".在有机会走出国门之前,还是先把祖国走一圈吧.都知道中 ...
- python怎么做软件程序_看 Python 超级程序员使用什么开发工具
Python超级程序员使用的开发工具 我以个人的身份采访了几个顶尖的Python程序员,问了他们以下5个简单的问题: 当前你的主要开发任务是什么? 你在项目中使用的电脑是怎样的? 你使用什么IDE开发 ...
- 绝对干货!Python 从业十年的程序员,写的万字经验分享
" 阅读本文大概需要 9 分钟. " 作者:laisky(基于 CC BY 4.0 授权许可) 原题:Python之路(内容略有调整) 来源:https://laisky.com/ ...
最新文章
- 好东西和大家分享阿!
- mysql auto_increment建表_在mysql表中创建一个ID auto_increment(在事实之后)
- 字符串互换后字典序最小
- [数据结构] 希尔排序
- SpringCloud组件 源码剖析:Eureka服务注册方式流程全面分析
- OJ系列之---IP与整数之间的转换
- Jackson 注解 -- 使用构造器
- php怎么调用css格式化,css文件格式化脚本的方法
- 以列表形式输出_04 Python之列表、集合和字典的推导式
- 判断用户是否存在再进行新增_基于tableau从商业分析模型角度对业务数据进行多维度分析--【商业分析类】...
- 剑指 offer 编程题 C++ 版总结(下)
- 前端学习(2781):底部tabber配置
- AJAX跨域请求的理解,JAVA
- asp.net处理get,post数据
- 转:Vss2005局域网开发权限设置指南
- 移动微技(Mobile Widget)应用开发权威指南
- 计算机趣味知识竞赛策划,大学生趣味知识竞赛活动的策划书
- 计算机程序有哪些性质,程序的特性有哪些
- python绘图画猫咪_Turtle库画小猫咪
- iOS高仿app源码:纯代码打造高仿优质《内涵段子》