Import statement that imports names from a module directly,statementimports,# Import sta


# Import statement that imports names from a module directly into the # importing module's symbol table.#//File: fibo.pydef fib(n):    # write Fibonacci series up to n    a, b = 0, 1    while b < n:        print b,        a, b = b, a+bdef fib2(n): # return Fibonacci series up to n    result = []    a, b = 0, 1    while b < n:        result.append(b)        a, b = b, a+b    return resultfrom fibo import fib, fib2fib(500)# There is even a variant to import all names that a module defines:from fibo import *fib(500)# This imports all names except those beginning with an underscore (_). 

评论关闭