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


Python Fraction.intersection方法代码示例

本文整理汇总了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
开发者ID:rlx310,项目名称:L_Python_Lutz_Learning-Python_Edition-5,代码行数:33,代码来源:Lutz_Ch_05.py

示例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'])
开发者ID:cluo,项目名称:learingPython,代码行数:33,代码来源:number.py


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