當前位置: 首頁>>代碼示例>>Python>>正文


Python operator.repeat方法代碼示例

本文整理匯總了Python中operator.repeat方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.repeat方法的具體用法?Python operator.repeat怎麽用?Python operator.repeat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在operator的用法示例。


在下文中一共展示了operator.repeat方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_repeat

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import repeat [as 別名]
def test_repeat(self):
        a = range(3)
        self.assertRaises(TypeError, operator.repeat)
        self.assertRaises(TypeError, operator.repeat, a, None)
        self.assertTrue(operator.repeat(a, 2) == a+a)
        self.assertTrue(operator.repeat(a, 1) == a)
        self.assertTrue(operator.repeat(a, 0) == [])
        a = (1, 2, 3)
        self.assertTrue(operator.repeat(a, 2) == a+a)
        self.assertTrue(operator.repeat(a, 1) == a)
        self.assertTrue(operator.repeat(a, 0) == ())
        a = '123'
        self.assertTrue(operator.repeat(a, 2) == a+a)
        self.assertTrue(operator.repeat(a, 1) == a)
        self.assertTrue(operator.repeat(a, 0) == '')
        a = Seq1([4, 5, 6])
        self.assertTrue(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6])
        self.assertTrue(operator.repeat(a, 1) == [4, 5, 6])
        self.assertTrue(operator.repeat(a, 0) == [])
        a = Seq2([4, 5, 6])
        self.assertTrue(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6])
        self.assertTrue(operator.repeat(a, 1) == [4, 5, 6])
        self.assertTrue(operator.repeat(a, 0) == [])
        self.assertRaises(TypeError, operator.repeat, 6, 7) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_operator.py

示例2: __repeat__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import repeat [as 別名]
def __repeat__(self):
        return Expression(self, operator.repeat) 
開發者ID:ebranca,項目名稱:owasp-pysec,代碼行數:4,代碼來源:expr.py

示例3: test_repeat

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import repeat [as 別名]
def test_repeat(self):
        a = range(3)
        self.failUnlessRaises(TypeError, operator.repeat)
        self.failUnlessRaises(TypeError, operator.repeat, a, None)
        self.failUnless(operator.repeat(a, 2) == a+a)
        self.failUnless(operator.repeat(a, 1) == a)
        self.failUnless(operator.repeat(a, 0) == [])
        a = (1, 2, 3)
        self.failUnless(operator.repeat(a, 2) == a+a)
        self.failUnless(operator.repeat(a, 1) == a)
        self.failUnless(operator.repeat(a, 0) == ())
        a = '123'
        self.failUnless(operator.repeat(a, 2) == a+a)
        self.failUnless(operator.repeat(a, 1) == a)
        self.failUnless(operator.repeat(a, 0) == '')
        a = Seq1([4, 5, 6])
        self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6])
        self.failUnless(operator.repeat(a, 1) == [4, 5, 6])
        self.failUnless(operator.repeat(a, 0) == [])
        a = Seq2([4, 5, 6])
        self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6])
        self.failUnless(operator.repeat(a, 1) == [4, 5, 6])
        self.failUnless(operator.repeat(a, 0) == [])
        if not test_support.is_jython:
            # Jython repeat is mul
            self.failUnlessRaises(TypeError, operator.repeat, 6, 7) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:28,代碼來源:test_operator.py


注:本文中的operator.repeat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。