学习笔记(18):零基础掌握 Python 入门到实战-重复利用,事半功倍

    科技2022-07-16  129

    立即学习:https://edu.csdn.net/course/play/26676/338764?utm_source=blogtoedu

    def function_name(x,y,z):

    定义函数名称

    do something return object 

    函数结束,返回值

    调用函数

    按照位置提供参数

    指明参数名称

    设置参数的默认值

    返回一个值/返回多个值

    >>> def my_fun():     return 1,2,3

    >>> r=my_fun() >>>  >>> r (1, 2, 3) >>> a=1,2,3,4 >>> a (1, 2, 3, 4) >>> a,b=1,2 >>> a 1 >>> b 2 >>> a,b,c=my_fun() >>> a 1 >>> b 2 >>> c 3

    >>> def fun(x,*args):     print("x=",x)     print("args=",args)

    >>> fun(1,2,3,4,5) x= 1 args= (2, 3, 4, 5) >>> def bar(x,**kwargs):     print('x=',x)     print('kwargs=',kwargs)

         >>> bar(1,a=2,b=3,c=4) x= 1 kwargs= {'a': 2, 'b': 3, 'c': 4} >>> 

    >>> def foo(*args,**kwargs):     print(args)     print(kwargs)

         >>> foo(1,2,3,a=9,b=8,c=7) (1, 2, 3) {'a': 9, 'b': 8, 'c': 7}

     

    相关资源:微信小程序源码-合集6.rar
    Processed: 0.008, SQL: 8