zoukankan      html  css  js  c++  java
  • python 函数相关

    [ 装饰器:]

    #!/usr/bin/env/ python

    from time import ctime

    def tsfunc(func):

    ~ def wrappedFunc():

    ~ ~ print '[%s] %s() called' % ( ctime(), func.__name__)

    ~ ~ return func()

    ~ return wrappedFunc

    @tsfunc

    def foo():

    ~ pass

    foo()     #=> [Sun Mar 19 22:50:28 2006] foo() called

    [ lambda: ]

    def usuallyAdd(x,y=2) : return x + y

    <=> lambda x,y=2 : x+y

    [ global: ]

    def foo():

    ~ bar = 200

    ~ print bar

    bar = 100

    print bar     #=> 100

    foo()           #=> 200

    print bar     #=> 100

    def foo2():

    ~ global bar

    ~ bar = 300

    ~ print bar

    print bar    #=> 100

    foo2()        #=> 300

    print bar    #=> 300

  • 相关阅读:
    作业
    Java总结
    十四周总结
    十二周课程总结
    十一周总结
    自我介绍
    第二次
    第十二周作业
    第九周作业
    第十三周课程总结
  • 原文地址:https://www.cnblogs.com/cly84920/p/4426611.html
Copyright © 2011-2022 走看看