本文整理汇总了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!")
示例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!")