python 函数小结

来源:互联网 发布:浙江师范行知学院宿舍 编辑:程序博客网 时间:2024/05/20 11:48

1.函数只有被调用才能使用

2. 输入的参数名不能有重名,并且需要有RETURN 返回值

3.常用的函数打印描述:

     print test2.__doc__

     var.append('ddd');原来的基础上增加字符串

一: 函数参数是字典的形式变量名与值

>>> def test2(**z):
    return z

>>> print test2(a=1,b=2,c=3)
{'a': 1, 'c': 3, 'b': 2}

运行结果如下:


四:列表的形式返回

>>> def test3(*z):
    return z

>>> print test3(1,2,3)
(1, 2, 3)

二: 通常的做法位置参数需要输入全部的参数

>>> def mytest(a,b,c):
    return a + b + c

>>> mytest(1,2,3)
6

三:可选的参数:   需要定义值

>>> def test(a=3,b=4,c=5):
    return a + b +c

>>> print test()
12
>>> print test(a=10)
19
>>> 



0 0
原创粉丝点击