Day04-python Basic Functions

Source: Internet
Author: User

A. Function objects: Functions are the first class of objects, that is, functions can be passed as data

1. Can be referenced

def foo ():     Print (' fromfoo') func=foo      ##foo值赋给了funcprint( Foo)    ##<function foo at 0x006e4108>print(func)   #  #<function foo at 0x006e4108>func ()        ##foo值赋给了func, so you can refer directly ()

2. Can be passed as parameters

def foo ():     Print ('fromfoo111111') def Bar (func):     Print (func)    func () bar (foo)

3. The return value can be a function

def foo ():     Print ('fromfoo') def Long (func):     return FUNCF=long (foo)print(f) f ()

4. Elements that can be used as container types

def foo ():     Print (' fromfoo'= {'fuck': foo}Print (dic['fuck') dic['fuck'] ()

defSelect (SQL):Print('------>select')defUpdate (SQL):Print('------>update')defDelete (SQL):Print('------>delete')defInsert (SQL):Print('------>insert') Fun_dit={    'Select': SELECT,'Update': Update,'Delete':d elete,'Insert': Insert}defMain (): whileTrue:sql= Input ('>>>:'). Strip ()if  notSql:ContinueL=sql.split () cmd=L[0]ifCmdinchFun_dit:fun_dit[cmd] (l) Main ()

Two. Nesting of functions

1. Nested calls to functions

def max2 (x, y    ): return if Else y def max4 (a,b,c,d):    res1=Max2 (A, b)    res2=max2 (res1,c)    res3=max2 ( res2,d)    return  res3print(max4 (10,80,31,20))

2. Function Nesting Definitions

def F1 ():     def F2 ():         Print ('fromfoo f2')         def f3 ():             Print ('fromfoo f3')        f3 ()    F2 () F1 ()

Day04-python Basic Functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.