码迷,mamicode.com
首页 > 编程语言 > 详细

第二天 Python3.4.2 函数

时间:2016-02-28 01:00:17      阅读:194      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!