• 函数


    #函数分为数学函数 和 程序开发函数
    #函数和过程
    
    #函数:
    #过程:就是没有return值
    
    #风湿理论:函数即变量
    
    
    #过程;在python中过程也是函数;
    def  test1():
        print("test1")
    
    #函数
    def  test2():
        print("test2")
        return "test2"
    
    #函数参数:
        # 1.形参变量只有在被调用时才分配内存单元,在调用结束时,即刻释放所分配的内存单元。因此,形参只在函数内部有效。函数调用结束返回主调用函数后则不能再使用该形参变量
        # 2.实参可以是常量、变量、表达式、函数等,无论实参是何种类型的量,在进行函数调用时,它们都必须有确定的值,以便把这些值传送给形参。因此应预先用赋值,输入等办法使参数获得确定值
    
    def calc(x,y):  #x,y 形参
        print(x,y)
    calc(1,3)          #1,3 实参
    
    
    #位置参数和关键字(标准调用:实参与形参位置一一对应;关键字调用:位置无需固定)
    def uuid(x,y,z):
        print(x)
        print(y)
        print(z)
    uuid(z=1,x=2,y=3)
    
    #默认参数
    def single(x="ok"):   #x="ok"默认参数
        print(x)
    single()
    
    
    #参数组 **字典  *列表
    def func(x,*args):
        print(x)          #func1
        print(args)     #(2, 3, 4, 5, 6)
    func("func",2,3,4,5,6,)
    
    
    def func1(x,*args):
        print(x)          #func1
        print(args)       #([2, 3, 4, 5, 6],)
    func1("func1",[2,3,4,5,6],)
    
    
    def func2(x,*args):
        print(x)          #func2
        print(args)       #(2, 3, 4, 5, 6)
    func2("func2",*[2,3,4,5,6],)        #*列表
    
    
    def itemsd(key,**kwargs):
        print(key)      #itemsd
        print(kwargs)   #{'x': 1, 'y': 2}
    itemsd("itemsd",x=1,y=2)
    
    
    def test(z,*args,**kwargs):
        print(z)            #1
        print(args)         #(2, 3, 4, 5, 6)
        print(kwargs)       #{'x': 2, 'y': 'kw'}
    test(1,2,3,4,5,6,x=2,y="kw")
    
    
    def test(z,*args,**kwargs):
        print(z)            #1
        print(args)         #('aa', 'bb', 'cc')
        print(kwargs)       #{'key': 'value'}
    test(1,*['aa','bb','cc'],**{'key':"value"})     #*列表   **字典
    
    
    #风湿理论验证:函数即变量
    def fengshi():
        print("风湿理论")
    
    def test():
        print("test")
        fengshi()
    test()
    
    
    # 高阶函数满足下面条件之一就是高阶函数
    # 1 把函数当作参数传递给另外一个函数
    # 2 返回值值包含函数
  • 相关阅读:
    css3
    css3
    npm 安装包无法继续下载? 卡住
    tcp/ip协议中的SYN, ACK的数值变化
    【转】6 Reasons Why JavaScript’s Async/Await Blows Promises Away (Tutorial)
    ES6 中 Symbol.split的用法
    Why does Typescript use the keyword “export” to make classes and interfaces public?
    es6中的import,export浏览器已经支持
    Understanding the JavaScript Engine—— two phase
    【转】js-ES6学习笔记-Symbol
  • 原文地址:https://www.cnblogs.com/ajaxa/p/8966866.html
Copyright © 2020-2023  润新知