# 创建模块fibo.py,里面的内容如下: deffib(n):# a, b = 0, 1 while b < n: print(b, end=' ') a, b = b, a+b print() deffib2(n):# return Fibonacci series up to n result = [] a, b = 0, 1 while b < n: result.append(b) a, b = b, a+b return result # 在解释器或脚本中import即可导入 >>> import fibo >>> fibo.fib(1000) 1123581321345589144233377610987 >>> fibo.fib2(100) [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>> fibo.__name__ 'fibo'
>>> from fibo import fib, fib2 >>> fib(500) 1123581321345589144233377
>>> from fibo import * # 引入fibo中所以内容,建议不使用这种方法 >>> fib(500) 1123581321345589144233377
>>> import fibo as fib >>> fib.fib(500) 01123581321345589144233377
>>> from fibo import fib as fibonacci >>> fibonacci(500) 01123581321345589144233377