Python-2
来源:互联网 发布:汉字域名百度收录吗 编辑:程序博客网 时间:2024/06/02 01:50
1. 自定义函数(可以有一个默认参数)
def function_name():
2. 传递函数arguements
return ()
def addMe(x): return x+xdef self(f,y): print (f(y))self(addMe,2)3. lambda函数
r=lambda x: x+xprint (r(5))
4. 递归
# the nth Fibonacci numberdef fib(n): a,b=0,1 count=1 while count < n: a,b=b,a+b count=count+1 print a
# the nth Fibonacci numberdef fib(n): if n==0 or n==1: return n else: return (fib(n-1)+fib(n-2))
5. 汉诺塔
# filename: Hanoi.pydef hanoi(a,b,c,n): if n==1: print(a,'->',c) else: hanoi(a,c,b,n-1) print(a,'->',c) hanoi(b,a,c,n-1)
若有n个盘子,共移动2的n次方-1次
6. 变量作用域
- 全局变量
- 局部变量
0 0
- python 2 & python 3
- Python--python基础知识(2)
- 【python】python基础知识2
- Python-(2)
- Python(2)
- python(2)
- Python - 2
- Python(2)
- Python-2
- python(2)
- Python 2
- python-2
- python(2)
- python 2 和 python 3
- Python-2 Python小程序
- Python 语言介绍--Python(2)
- Python print 语句(Python 2 与 Python 3)
- Python 初学者 入门 应该学习 python 2 还是 python 3?
- 笔试选择题二十八
- 虚函数
- Linux中如何替换文件名中的空格
- POJ - 1742 Coins(多重背包)@
- 对象如何持久化(用json_encode)?
- Python-2
- Matlab中二进制数据文件的读写
- 记录Ubuntu的一些小常识
- HDU 1558 (并查集+判断线段相交)
- 382. Linked List Random Node
- Quartz.NET教程_Lesson 6: CronTrigger
- C#控制台基础 为什么存在部分类 partial
- 几个经常用到的字符串的截取
- ios 利用NSStream模拟请求http数据