本文整理匯總了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)
示例2: __repeat__
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import repeat [as 別名]
def __repeat__(self):
return Expression(self, operator.repeat)
示例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)