python学习足迹(2)
2004-08-09 13:28
525 查看
1,Python中的数据类型。
NoneType, TypeType(自定义类型), IntType, LongType, FloatType, ComplexType(复数), StringType, UnicodeType,TupleType, ListType, DictType, FunctionType
LongType在python中是没有长度限制的,这个也是script的优点。
2,filter(), map(), reduce()
filter(function, list) return list. 筛选规律是 function = true Example:
>>>def f(x): return x %2 != 0
...
filter(f, range(2,10) ), 结果是3,5,7,9
map(function, list), return list, 规律是对list进行运算。
>>> def f(x): return x*x
...
>>> map(f,range(1,10))
[1, 4, 9, 16, 25, 36, 49, 64, 81]
reduce类似进行累加,
>>> def add(x,y): return x+y
...
>>> reduce(add,range(1,11))
55
3,用del来删除list中的元素:
>>> a=[0,1,2,3,4]
>>> del a[0]
>>> a
[1, 2, 3, 4]
>>> del a[1:3]
>>> a
[1, 4]
4,if ... elif ...else 结构。不是elseif啊。
5,raw_input用来得到用户的输入,象Console.ReadLine()
>>> a=raw_input("Your name: ")
Your name: hacker.net
>>> a
'hacker.net'
6, while 循环:
while <条件>:
语句(注意缩进)
7, for 循环:
for var in <list or string>:
语句(缩进)
>>> for str in "hello,world":
... print str
>>> l=['a','b','c']
>>> for s in l:
... print s,
...
a b c
8, try, except:
try:
语句
except:
语句
9,range函数:返回一个list
range(10) = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
range(5,10) = [5, 6, 7, 8, 9]
range(1,10,2) =[1, 3, 5, 7, 9]
range(10,1,-1) = [10, 9, 8, 7, 6, 5, 4, 3, 2]
经常用的遍历方法,构造一个range
>>> a=['a','b','c']
>>> for i in range(len(a)):
... print a[i],
...
a b c
NoneType, TypeType(自定义类型), IntType, LongType, FloatType, ComplexType(复数), StringType, UnicodeType,TupleType, ListType, DictType, FunctionType
LongType在python中是没有长度限制的,这个也是script的优点。
2,filter(), map(), reduce()
filter(function, list) return list. 筛选规律是 function = true Example:
>>>def f(x): return x %2 != 0
...
filter(f, range(2,10) ), 结果是3,5,7,9
map(function, list), return list, 规律是对list进行运算。
>>> def f(x): return x*x
...
>>> map(f,range(1,10))
[1, 4, 9, 16, 25, 36, 49, 64, 81]
reduce类似进行累加,
>>> def add(x,y): return x+y
...
>>> reduce(add,range(1,11))
55
3,用del来删除list中的元素:
>>> a=[0,1,2,3,4]
>>> del a[0]
>>> a
[1, 2, 3, 4]
>>> del a[1:3]
>>> a
[1, 4]
4,if ... elif ...else 结构。不是elseif啊。
5,raw_input用来得到用户的输入,象Console.ReadLine()
>>> a=raw_input("Your name: ")
Your name: hacker.net
>>> a
'hacker.net'
6, while 循环:
while <条件>:
语句(注意缩进)
7, for 循环:
for var in <list or string>:
语句(缩进)
>>> for str in "hello,world":
... print str
>>> l=['a','b','c']
>>> for s in l:
... print s,
...
a b c
8, try, except:
try:
语句
except:
语句
9,range函数:返回一个list
range(10) = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
range(5,10) = [5, 6, 7, 8, 9]
range(1,10,2) =[1, 3, 5, 7, 9]
range(10,1,-1) = [10, 9, 8, 7, 6, 5, 4, 3, 2]
经常用的遍历方法,构造一个range
>>> a=['a','b','c']
>>> for i in range(len(a)):
... print a[i],
...
a b c
相关文章推荐
- python学习足迹(1)
- Python学习足迹(3)
- Python学习足迹(4)(入门篇终结)
- Python 学习入门(9)—— set操作
- Django学习笔记1——win10下安装pip与python环境【django环境部署I】
- Python Requests-学习笔记(9)-错误与异常
- Zookeeper学习笔记 --- Python实现向zookeeper中写入配置数据
- python学习笔记(二)图片标注工具LabelImg
- python 日志模块logging学习与使用(日志分割)
- 【Python】学习笔记十:字典
- Python模块学习:glob 文件路径查找
- Python学习笔记:面向对象基础
- [转] python 模块学习 hashlib
- 学习笔记之Python数据类型-String
- python学习笔记
- python学习笔记-高级特性-切片(Slice)
- Python --- 第二周周五学习内容
- python数据结构学习笔记-2016-10-17-03-多维数组
- 新手学习selenium 2.0+python 2.7.11+firefox46的环境配置
- Python学习:HTML表单