07-缺省参数
发布日期:2021-05-14 21:58:03 浏览次数:17 分类:博客文章

本文共 2196 字,大约阅读时间需要 7 分钟。

������������

���������������������������������������������������������������������������������������������������������������������������������������������������

������1���

#-*- coding:utf-8 -*-def test(a,b):������#���������������������������a���b    result = a+b    print("result=%d"%result)test(11,22)������#������������������������������test(22,22)test(33,22)root@ubuntu:/home/python/codes/python������-05# python2 test.py result=33result=44result=55

������������������������������������������������������������������������������������������������������������������test������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

#-*- coding:utf-8 -*-def test(a,b=22):������#���������b=22������������������    result = a+b    print("result=%d"%result)test(11)test(22)test(33)root@ubuntu:/home/python/codes/python������-05# python3 test.py result=33result=44result=55

������2���

���������������������help()������������������������������������������������������������������������

In [1]: help(print)Help on built-in function print in module builtins:print(...)    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)������#end='\n'������������������������������������������������������������������������������������������������        Prints the values to a stream, or to sys.stdout by default.    Optional keyword arguments:    file:  a file-like object (stream); defaults to the current sys.stdout.    sep:   string inserted between values, default a space.    end:   string appended after the last value, default a newline.    flush: whether to forcibly flush the stream.

������3���

In [2]: def test(a,b=22,c=33):������#���������������������������b���c������������������������������   ...:     print(a)   ...:     print(b)   ...:     print(c)   ...:     In [3]: test(11,c=44)������#������������������������a���������11,c���������44112244
上一篇:08-不定长函数
下一篇:牛逼!Java 从入门到精通,超全汇总版

发表评论

最新留言

很好
[***.229.124.182]2025年04月21日 22时17分16秒