python中set的用法:取交集的简单示例

前端之家收集整理的这篇文章主要介绍了python中set的用法:取交集的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
set函数基本用法感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
python代码如下:

# python中set函数基本用法示例(编程之家 jb51.cc整理)

se = {11,22,33}
be = {22,55}

temp1 = se.intersection(be)             #取交集,赋给新值
print(temp1)  # 22
print(se)  # {11,33}

temp2 = se.intersection_update(be)      #取交集并更新自己
print(temp2)  # None
print(se)  # 22

# 来自jb51.cc 
原文链接:https://www.f2er.com/python/527358.html

猜你在找的Python相关文章