Python学习要点:
1、基本数据类型
2、如何自定义数据结构
3、if for while 语句
4、系统调用如何使用
5、多线程如何操作
一、python数据类型
1.1、字符串
a、使用单引号(')
用单引号括起来表示字符串,例如:
str='this is string';
print str;
b、使用双引号(")
双引号中的字符串与单引号中的字符串用法完全相同,例如:
str="this is string";
print str;
c、使用三引号(''')
利用三引号,表示多行的字符串,可以在三引号中自由的使用单引号和双引号,例如:
str='''this is string
this is pythod string
this is string'''
print str;
bool=False;
print bool;
bool=True;
print bool;
1.3、整数
int=20;
print int;
1.4、浮点数
float=2.3;
print float;
1.5列表
list=['physics', 'chemistry', 1997, 2000];
nums=[1, 3, 5, 7, 8, 13, 20];
1.5.1 遍历列表
for element in list:
print element
1.5.2获得列表长度
nlen = len(list)
1.5.3自动生成数字列表
numList = range(len(list))
print numList
结果:[0,1,2,3]
1.6元组
Python的元组与列表类似,不同之处在于元组的元素不能修改;元组使用小括号(),列表使用方括号[];元组创建很简单,只需要在括号中添加元素,并使用逗号(,)隔开即可,例如:
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5 );
tup3 = "a", "b", "c", "d";
1.7字典
字典(dictionary)是除列表之外python中最灵活的内置数据结构类型。列表是有序的对象结合,字典是无序的对象集合。两者之间的区别在于:字典当中的元素是通过键来存取的,而不是通过偏移存取。
dict = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'};
1.8文件操作
例子:f = open(fileName, "r")
while True:
line = f.readline()
if line:
if len(line) > 2:
print line
filelist.append(line)
else:
print "null..........."
else:
break
打开文件:f = open(filename, flag)
读取行: line = f.readline() 读取完毕收,返回空