字符串分割
例:sentenc = "I am an Englist sentenc"
sentence.split()
split()把字符串按照空格进行分割,所以得到的结果是
['I','am','an','Englist','sentenc']字符串的空格不存在
除空格外也可按照【\n】、制表符【\t】进行分割 split默认按照空白字符进行分割
按照指定分割符号来分割” . “
section = 'Hi.I am the one.Bye.'
section.split('.')
得到
['Hi','I am the one','Bye','']
例:'aaaa'.split('a')
得到:['','','','','']
二、打开一个文件 file('文件名')
f = file('文件名')
data = f.read()
print data
f.close()
三、写文件
f = file('output.txt', 'w')若文件不存在自动创建
open()用法
data = 'I will be in file.\nSo cool'
out = open('output.txt'