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

  • 相关阅读:
    MYSQL[34]
    MYSQL[32]
    mysql字符集的问题
    MYSQL[31]
    开源RPC框架简介
    MYSQL[35]
    版本号的表示方法
    MYSQL[29]
    MYSQL[39]
    hdu 1166【树状数组】
  • 原文地址:https://www.cnblogs.com/cly84920/p/4426611.html
Copyright © 2011-2022 走看看