zoukankan      html  css  js  c++  java
  • python基础--函数作用域

    name="alex"
    def foo():
        name="tang"
        #print(name)
        def bar():
    
            print(name)
        return bar#函数名代表得就是一个函数的内存地址
    # a=foo()
    # print(a)
    # print(a())
    foo()()#由于函数bar包含在函数foo()中,所以bar会在自身查找打印的变量,如果没找到去往上一级查找,最后查找全局
    #python编译器是按照顺序加载的,在调用foo()时函数bar被加载,所以必须要按照加载顺序调用函数,return返回的是函数名及函数在内存中的地址,所以可以直接使用foo()()调用
    # def test1(): # print('in the test1') # return 1 # # def test(): # print("in the test") # return test1() # # #print(test) # a=test() # print(a) # def test1(): # print('in the test1') # #return 1 # # def test(): # print("in the test") # return test1 # # #print(test) # res=test() # print(res())
    如果我失败了,至少我尝试过,不会因为痛失机会而后悔
  • 相关阅读:
    交换机技术
    第七周课后总结
    以太网原理
    test
    NetCore第一步:千里之行 始于环境构筑
    第二十课(一)
    第十九课(三)
    第十九课(二)
    第十九课(一)
    第十八课(三)
  • 原文地址:https://www.cnblogs.com/tangcode/p/10984094.html
Copyright © 2011-2022 走看看