继续学习python基础教程。
第三章 使用字符串
基本字符串操作:索引,分片,乘,判断成员, 求长度,max,min(以上是序列,对字符串也可以,但是要知道:字符串不可以改变!!!)因此:

字符串格式化
格式化操作符%(ps%也是求余的操作符)

格式化实数 %.3f 保留三位小数
模版字符串:string模块

字段宽度和精度

>>> "%.*s" % (5,"guido van rossium")
'guido' 可以使用*作为字段宽度或精度,可以从元组参数中读出
字符串方法
1、find 与in不同,in只能查找单个字符。subject="youyouyouyou" subject.find("you",1,4) 可以提供起始位点和结束位点,如没有,返回-1
2、 join split方法逆方法

3、lower转化为小写。 string的capwords得到标题形式
4、replace 替换所有匹配项
5、split "1+2+3".split("+") 如果不提供分割符,则默认空格
6、strip 去除两侧的空格 比如得到对方输入时,多输入了空格,使用strip就得到有用字符串
也可以去除指定字符 "****you are hhh !!!****".strip("!*")
7、translate 也是替换,但是单字符,优势在于可以同时多个替换
用string的maketrans函数 table=maketrans("cs","kz") 第一个字符串中每个字符用第二个中相应位置的字符替换。
"this is a test".translate(table," ") 第二个参数可以用来指定要删除的字符。
今天做了一个小练习,删除snp calling中call多碱基的情况:


所以,函数调用的时候要注意调用的作用方式,是否会改变原对象。可以定义一个新变量承接这个函数的输出。


使用while True是因为文件过大。
网友评论