split作为分隔的方式
占据着一壁江山
下面就几个例子说明
# a=['a','h','e']
print('a,h,e'.split(','))
print('a b h'.split())#空格输出列表
print("a\nb\nc".split())#换行输出为列表
print('a**n**g'.split('**'))
特别注意的是换行和空格的分割都是使用split()
其他则带相应字符
#join方法的使用
以格式化遍历输出文档内容的方式
filelist=open(‘demo1_test1.txt’,‘r’)
liname=[list1.strip() for list1 in filelist]
print(liname)
filelist.close()
输出的结果:
```python
# 对于由数字组成的代码,我们可以这样
filelist=open('demo1_test1.txt','r')
liname=[eval(list1) for list1 in filelist]
print(liname)
filelist.close()
输出的结果
#使用列表和元组的组合能做意想不到的计算
#{0:.2f}表示保留两位小数点
#否则表示不保留小数点
monneyall=[("north",65),("west",80),("blight",112),("night",89)]
total=monneyall[0][1]+monneyall[1][1]+monneyall[2][1]+monneyall[3][1]
print("total about the year monneyall:{0:.2f} bilion".format(total))