当前位置: 首页>>代码示例>>Python>>正文


Python strop.replace方法代码示例

本文整理汇总了Python中strop.replace方法的典型用法代码示例。如果您正苦于以下问题:Python strop.replace方法的具体用法?Python strop.replace怎么用?Python strop.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在strop的用法示例。


在下文中一共展示了strop.replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_replace

# 需要导入模块: import strop [as 别名]
# 或者: from strop import replace [as 别名]
def test_replace(self):
        replace = strop.replace
        self.assertTrue(replace("one!two!three!", '!', '@', 1)
                     == "one@two!three!")
        self.assertTrue(replace("one!two!three!", '!', '@', 2)
                     == "one@two@three!")
        self.assertTrue(replace("one!two!three!", '!', '@', 3)
                     == "one@two@three@")
        self.assertTrue(replace("one!two!three!", '!', '@', 4)
                     == "one@two@three@")

        # CAUTION: a replace count of 0 means infinity only to strop,
        # not to the string .replace() method or to the
        # string.replace() function.

        self.assertTrue(replace("one!two!three!", '!', '@', 0)
                     == "one@two@three@")
        self.assertTrue(replace("one!two!three!", '!', '@')
                     == "one@two@three@")
        self.assertTrue(replace("one!two!three!", 'x', '@')
                     == "one!two!three!")
        self.assertTrue(replace("one!two!three!", 'x', '@', 2)
                     == "one!two!three!") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:25,代码来源:test_strop.py

示例2: test_replace

# 需要导入模块: import strop [as 别名]
# 或者: from strop import replace [as 别名]
def test_replace(self):
        replace = strop.replace
        self.assert_(replace("one!two!three!", '!', '@', 1)
                     == "one@two!three!")
        self.assert_(replace("one!two!three!", '!', '@', 2)
                     == "one@two@three!")
        self.assert_(replace("one!two!three!", '!', '@', 3)
                     == "one@two@three@")
        self.assert_(replace("one!two!three!", '!', '@', 4)
                     == "one@two@three@")

        # CAUTION: a replace count of 0 means infinity only to strop,
        # not to the string .replace() method or to the
        # string.replace() function.

        self.assert_(replace("one!two!three!", '!', '@', 0)
                     == "one@two@three@")
        self.assert_(replace("one!two!three!", '!', '@')
                     == "one@two@three@")
        self.assert_(replace("one!two!three!", 'x', '@')
                     == "one!two!three!")
        self.assert_(replace("one!two!three!", 'x', '@', 2)
                     == "one!two!three!") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:25,代码来源:test_strop.py


注:本文中的strop.replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。