Python ပြည်ထောင်စု intersection_update() စနစ်
အကြိမ်
ပြည်ထောင်စု x နှင့် ပြည်ထောင်စု y တွင် မရှိသေးသော အရာများ ဖျက်သိမ်းပါ
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"} x.intersection_update(y) print(x)
定义和用法
intersection_update() 方法会删除各集合中都不存在的项目。
intersection_update() 方法与 intersection() 方法不同,因为 intersection() 方法返回一个新集合,其中没有不需要的项目,而 intersection_update() 方法从原始集中删除了不需要的项目。
语法
set.intersection_update(set1, set2 ... etc)
参数值
参数 | 描述 |
---|---|
set1 | 必需。要在其中检索相等项目的集合。 |
set2 |
可选。要在其中检索相等项目的另一集合。 您能够比较任意多的集合。 အချက်အလက် အကြား ခွဲခြား |
အကြိမ် ပိုမို
အကြိမ်
3 ခု စည်းကမ်း နှင့် နှင့် အပြင် နှင့် အပြင် နှင့် အပြင် အချက်အလက် တွင် အချက်အလက် အချက်အလက် ပါဝင်သော အချက်အလက် ကို ပါဝင်သည်
x = {"a", "b", "c"} y = {"c", "d", "e"} z = {"f", "g", "c"} x.intersection_update(y, z) print(x)