本文整理汇总了Python中fractions.Fraction.intersection方法的典型用法代码示例。如果您正苦于以下问题:Python Fraction.intersection方法的具体用法?Python Fraction.intersection怎么用?Python Fraction.intersection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fractions.Fraction
的用法示例。
在下文中一共展示了Fraction.intersection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import intersection [as 别名]
x = set('abcde')
y = set('bdxyz')
print(x)
print(y)
print(x - y) # Difference
print(x | y) # Union
print(x & y) # Intersection
print(x ^ y) # Symmetric difference
print(x > y, x < y) # Superset, subset
print('e' in x) # Membership
print('e' in 'Camelot', 22 in [11, 22, 33]) # Works with other types as well
z = x.intersection(y) # Same as x & y
print(z)
z.add('SPAM') # Insert one item
print(z)
z.update({'X', 'Y'}) # Merge: in-place union
print(z)
z.remove('b') # Delete one item
print(z)
for item in set('abc'):
print(item * 3)
S = set([1, 2, 3])
print(S | set([3, 4])) # Expressions require both to be sets
# print(S | [3, 4])
print(S.union([3, 4])) # But their methods allow any iterable
示例2: set
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import intersection [as 别名]
print ret
ret = decimal.Decimal(str(1/3)) + decimal.Decimal(str(6/12))
print ret
x = set('abcde')
y = set('bdxyz')
print x,y
print 'e' in x;
print x - y #diff
print x | y #union
print x & y #inntersection
print x ^ y
z = x.intersection(y)
z.add('SPAM')
print z
z.update(set(['X','Y']))
print z
z.remove('b')
print z
for item in set('abc'): print(item * 3) #set
print z | set([3, 4])
ret = z.union([5,6])
print ret
ret = ret.intersection([1,3,5]);
print ret
S = {1,2,3,4}
S.add('alot')
S.update(['a','l','o','t'])