zoukankan      html  css  js  c++  java
  • Python replace()方法

    描述

    Python replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。

    语法

    replace()方法语法:

    str.replace(old, new[, max])
    

    参数

    • old -- 将被替换的子字符串。
    • new -- 新字符串,用于替换old子字符串。
    • max -- 可选字符串, 替换不超过 max 次

    返回值

    返回字符串中的 old(旧字符串) 替换成 new(新字符串)后生成的新字符串,如果指定第三个参数max,则替换不超过 max 次。

    实例

    以下实例展示了replace()函数的使用方法:

    #!/usr/bin/python
    
    str = "this is string example....wow!!! this is really string";
    print str.replace("is", "was");
    print str.replace("is", "was", 3);
    

    以上实例输出结果如下:

    thwas was string example....wow!!! thwas was really string
    thwas was string example....wow!!! thwas is really string

    转自:http://www.runoob.com/python/att-string-replace.html
    最近开始学起了python,写了一个xss扫描器,遇到了很多问题,在接下来的日子里,我会把这些感悟和看过的资料写或者装载到博客,仅仅作为自己以后查阅的一个途径。
    每天学习一点点!
  • 相关阅读:
    【转载】C++汇编器、连接器
    【转载】vi的使用命令
    JDK,SDK,JRE概念
    iOS 使用xmpp做聊天客户端
    cocopods安装
    用XMPP实现完整Android聊天项目
    xmpp发送文件
    ember.js学习笔记
    html5 drag and drop
    jquery 数组深拷贝
  • 原文地址:https://www.cnblogs.com/Heart-J/p/4881344.html
Copyright © 2011-2022 走看看