Python&replace()方法

DrCrypto
博客专家认证
2014-03-07 10:18:59

令s="TTATGTTTTAAGGATGGGG"
s.replace(s[:2],'')
输出:'ATGAAGGATGGGG'
可是为什么少了4个T???
...全文
265 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zd357 2014-03-14
  • 打赏
  • 举报
回复
s.replace(s[:2],'') 不就是s.replace("TT" ,'')吗,把s里的TT都换成空,所以TT都没了。
李察德-泰森 2014-03-07
  • 打赏
  • 举报
回复

>>> help(s.replace)
Help on built-in function replace:

replace(...)
    S.replace(old, new[, count]) -> string
    
    Return a copy of string S with all occurrences of substring
    old replaced by new.  If the optional argument count is
    given, only the first count occurrences are replaced.
这是replace的说明,看了你就知道了

37,718

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧