Python学习笔记 发表于 2017-02-27 Python 中简单的运算加(+)1234def add(a,b): return a + bprint add(1, 2) // 3 减(-)1234def sub(a, b): return a - bprint add(2, 1) // 1 乘(×)1234def sun(a, b): return a * bprint add(1, 2) // 2 除(÷)1234def divided(a, b): return a / bprint add(2, 1) // 2 Python 实现斐波那契数列方法一123456def fibo(num): numList = [0,1] for i in range(num - 2): numList.append(numList[-2] + numList[-1]) return numList 方法二123456def fibo(n): x, y = 0, 1 while(n): x,y,n = y, x+y, n - 1 return x 方法三12345678910def fibo(n): def fib_iter(n,x, y): if n == 0: return x else: return fib_iter(n-1, y, x+y) return fib_iter(n, 0, 1)print fibo(3) 其实写我博客这是为了记录一些好玩的东西,做笔记也是一样的 Enjoy it ? Donate me ! 欣赏此文?求鼓励,求支持! 赏 微信打赏 支付宝打赏