美文网首页
【编程】python入门——函数03

【编程】python入门——函数03

作者: 小不点Grace | 来源:发表于2020-06-15 22:20 被阅读0次

    坚持!

    位置参数和关键字参数使用的区别

    01位置参数

    print('hello','world')
    

    print('hello','world'):是位置参数


    02关键字参数:end=''(不换行);sep=''(指定分割符)
    空字符:里面什么也没有;空格字符:里面有空格

    print('hello',end='')
    

    end='' :关键字参数_____end:参数名;'':参数值

    print('hello','world')
    

    注:数据与数据之间默认用空格进行分割

    运行结果
    print('hello','world',sep=',')
    
    运行结果
    注:sep指定输出时,数据与数据之间用何种字符进行分割
    sep=''与end='' 可以同时指定
    print('hello','world',sep='-',end=' ')
    print('hello','world')
    
    运行结果

    关键字参数:需要放在所有正常参数的末尾,但是关键字参数之间没有顺序之分

    通过关键字参数指定 a 和 b 的值

    def add(a,b):
        print(a+b)
    add(a=90,b=20) #通过关键字参数指定 a 和 b 的值,先后顺序不分
    

    最近任务有点多,脑壳有点疼。

    相关文章

      网友评论

          本文标题:【编程】python入门——函数03

          本文链接:https://www.haomeiwen.com/subject/mtqkxktx.html