Python os 模块提供了一个统一的操作系统接口函数 一、对于系统的操作 1、os.name 当前使用平台 其中 ‘nt’ 是 windows,’posix’ 是linux 或者 unix 2、os.sep 输出操作系统的特定的路径分隔符。Win下为“\”,Linux下为“/” 3、os.pat Read More
posted @ 2017-06-13 14:44 emily-qin Views(4407) Comments(1) Diggs(1) Edit
一、创建 1、创建文件 open(path,'w') 2、创建目录 (1)os.mkdir(pt[, mode=0777]) 新建一个目录pt,参数mode表示生成的目录的权限,默认是超级权限,也就是0777。 (2)os.makedirs(pt) 创建多级目录 比如在python目录下创建\t1\ Read More
posted @ 2017-06-13 14:40 emily-qin Views(948) Comments(0) Diggs(0) Edit
一、open函数:对文件读写之前,需要先打开文件,获取文件句柄 注意:open() file() 尽量使用open(),Python3以后不支持file()了 1、open(file_name[,access_mode][,buffering]) (1)参数说明 file_name:一个包含了你要访 Read More
posted @ 2017-06-13 14:33 emily-qin Views(16431) Comments(0) Diggs(1) Edit
一、过滤字符串 1、strip() (1)去掉行收尾不可见字符 a = ' wejifrow ' print a print a.strip() 结果: wejifrow wejifrow (2)strip([chars]) a = '**weji**frow**' print a.strip('* Read More
posted @ 2017-06-12 18:56 emily-qin Views(428) Comments(0) Diggs(0) Edit
一、字符串类型 1、普通字符串 s1='abef\neiwo' print s1 print type(s1) 结果: abef eiwo <type 'str'> 2、原始字符串 s2=r'abef\neiwo' print s2 print type(s2) 结果abef\neiwo <type Read More
posted @ 2017-06-12 18:54 emily-qin Views(208) Comments(0) Diggs(0) Edit
一、set集合 1、集合是一个无序不重复元素集,有去重的作用 set集合类需要的参数必须是迭代器类型的,如:序列、字典等,然后转换成无序不重复的元素集。由于集合是不重复的,所以可以对字符串、列表、元组进行去重操作。 (1)创建 s1=set('This is string') ([]) set1=s Read More
posted @ 2017-06-12 18:52 emily-qin Views(224) Comments(0) Diggs(0) Edit
一、序列 1、列表、元组和字符串都是序列 二、序列的两个特点:索引操作符和切片操作符 1、索引操作符:从序列中抓取一个特定项目 下标操作:使用索引获取序列中的单个项目: eg:shoplist[0] 序列的第一个项目; shoplist[-1] 序列的最后一个项目 2、切片操作符:获取序列的一个切片 Read More
posted @ 2017-06-12 18:52 emily-qin Views(190) Comments(0) Diggs(0) Edit
key值需要是不可变对象,字典没有顺序 1、声明一个字典 dictA={ } 2、字典添加元素 dictA['name']='jack' dictA['age']=19 dictA['sex']='male' 声明字典的第二种方式 dictB={'name':'cindy','addr':'Chin Read More
posted @ 2017-06-12 18:51 emily-qin Views(387) Comments(0) Diggs(0) Edit
一、元组 tupleA=(1,2,3,4,5,6) print tupleA 1、元组支持的运算符 tup1+tup2 tup1*2 3 in tup2 for i in tup2: print i tup2 is tup1 元组支持的内置函数 len(tup1) cmp(tup1,tup2) ma Read More
posted @ 2017-06-12 18:50 emily-qin Views(440) Comments(0) Diggs(0) Edit
列表:处理一组有序项目的数据结构 一、基本操作 1、列表运算符 list1=[2,3,4,5,6,7,8] print len(list1) print [1,2]+[3,4] print ['Hi']*4 print 4 in list1 for i in list1: print i list2 Read More
posted @ 2017-06-12 18:47 emily-qin Views(339) Comments(0) Diggs(0) Edit