作用域

def input():
    print("in put now")

def func():
    input()
func()


def input():
    print("in put now")

def func():
    input=1
    print(input)

func()


def max(l):
    print("in max func")
print(max([1,2,3]))

def outer():
    a=1
    def inner():
        print(a)
    inner()
outer()

def outer():
    a=1
    def inner():
        print(a)
    return inner
inn=outer()
inn()

def outer():
    a=1
    def inner():
        print(a)
    print(inner.__closure__)
outer()
print(outer.__closure__)

def func():
    print('123')



def haha(f):

    return f

hehe=haha(func)
hehe()

def func():
    print('123')
func2=func
func2()
l=[func,func2]
print(l)
for i in l:
    i()



a=0
def haha():
    a=1
    def hehe():
       b=2
       print(a)
       print("hehe")
       def gg():
         global a
         print(gg)
         a+=1
         print("gg")
       gg()

    hehe()
    print("777",a)
haha()
print("888",a)

def max(a,b):
    return a if a>b else b


def the_max(x,y,z):
    c = max(x,y)
    return max(c,z)

v=the_max(1,2,3)
print(v)

a=1
b=2
def func():
    x="aaa"
    y="bbb"
    print(locals())
    print(globals())

func()


a=1
def func():
    global a
    a+=1
    a=5

func()
print(a)
上一篇:jquery --入门


下一篇:《Java编程思想》读书笔记10.内部类