首页 > 编程语言 > 详细

第二天 Python3.4.2 函数

时间:2016-02-28 00:58:36      阅读:243      评论:0      收藏:0      [点我收藏+]

1.什么是函数

1.1 函数是组织好的,可以重复使用的,实现单一功能的代码段

1.2 函数有输入(参数)和输出(返回值)

1.3 python中,函数是一等对象(first clas)

 

函数的定义与调用:

In [33]: def fn():
   ....:     pass
   ....: 

In [34]: fn()

In [35]: def fn():
   ....:     print (test fn)
   ....:     

In [36]: fn()
test fn

如果里面有赋值,创建新的变量,没有赋值,就用原来的变量的值。

 

In [43]: lst=[1,2,3]

In [44]: def append(item):
   ....:     lst.append(item)
   ....:     

In [45]: append(4)

In [46]: lst
Out[46]: [1, 2, 3, 4]

 

第二天 Python3.4.2 函数

原文:http://www.cnblogs.com/tom-li/p/5223933.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!