博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ntp symmetric_Python使用示例设置symmetric_difference_update()方法
阅读量:2528 次
发布时间:2019-05-11

本文共 2556 字,大约阅读时间需要 8 分钟。

ntp symmetric

设置symmetric_difference_update()方法 (Set symmetric_difference_update() Method)

symmetric_difference_update() method is used to get the list of all elements which are not common in both sets and update this set (set1) with these elements or we can say this method is used to update this set (set1) by removing the elements which are common in both sets.

symmetric_difference_update()方法用于获取两个集合中都不通用的所有元素的列表,并使用这些元素更新该集合( set1 ),或者我们可以说此方法用于通过删除以下元素来更新此集合( set1 ):在这两种情况下都很常见。

Syntax:

句法:

set1.symmetric_difference_update(set2)

Parameter(s):

参数:

  • set2 – It represents another set to be compared with this set (set1).

    set2 –代表另一个要与此集合进行比较的集合( set1 )。

Return value:

返回值:

The return type of this method is <class 'NoneType'>, it updates this set (set1) by removing the elements which are common in both sets.

此方法的返回类型为<class'NoneType'> ,它通过删除两个集合中共同的元素来更新此集合( set1 )。

Example 1:

范例1:

# Python Set symmetric_difference_update() # Method with Example# declaring the setscars_1 = {
"Porsche", "Audi", "Lexus"}cars_2 = {
"Porsche", "Mazda", "Lincoln"}# printing sets before symmetric_difference_update()print("Before calling symmetric_difference_update()...")print("cars_1:", cars_1)print("cars_2:", cars_2)# symmetric_difference_update() method callcars_1.symmetric_difference_update(cars_2)# printing sets after symmetric_difference_update()print("After calling symmetric_difference_update()...")print("cars_1:", cars_1)print("cars_2:", cars_2)

Output

输出量

Before calling symmetric_difference_update()...cars_1: {'Audi', 'Lexus', 'Porsche'}cars_2: {'Porsche', 'Mazda', 'Lincoln'}After calling symmetric_difference_update()...cars_1: {'Mazda', 'Audi', 'Lincoln', 'Lexus'}cars_2: {'Porsche', 'Mazda', 'Lincoln'}

Example 2:

范例2:

# Python Set symmetric_difference_update() ##Method with Example# declaring the setsx = {
"ABC", "PQR", "XYZ"}y = {
"ABC", "PQR", "XYZ"}z = {
"DEF", "MNO", "ABC"}# printing the resultsprint("Before calling symmetric_difference_update()...")print("x:", x)print("y:", y)print("z:", z)# printing the result of # symmetric_difference_update()x.symmetric_difference_update(y)y.symmetric_difference_update(z)z.symmetric_difference_update(x)# printing the resultsprint("After calling symmetric_difference_update()...")print("x:", x)print("y:", y)print("z:", z)

Output

输出量

Before calling symmetric_difference_update()...x: {'ABC', 'XYZ', 'PQR'}y: {'ABC', 'XYZ', 'PQR'}z: {'ABC', 'MNO', 'DEF'}After calling symmetric_difference_update()...x: set()y: {'XYZ', 'MNO', 'DEF', 'PQR'}z: {'ABC', 'MNO', 'DEF'}

翻译自:

ntp symmetric

转载地址:http://bkvzd.baihongyu.com/

你可能感兴趣的文章
P1313 计算系数
查看>>
NSString的长度比较方法(一)
查看>>
Azure云服务托管恶意软件
查看>>
My安卓知识6--关于把项目从androidstudio工程转成eclipse工程并导成jar包
查看>>
旧的起点(开园说明)
查看>>
生产订单“生产线别”带入生产入库单
查看>>
crontab导致磁盘空间满问题的解决
查看>>
java基础 第十一章(多态、抽象类、接口、包装类、String)
查看>>
Hadoop 服务器配置的副本数量 管不了客户端
查看>>
欧建新之死
查看>>
自定义滚动条
查看>>
APP开发手记01(app与web的困惑)
查看>>
笛卡尔遗传规划Cartesian Genetic Programming (CGP)简单理解(1)
查看>>
mysql 日期时间运算函数(转)
查看>>
初识前端作业1
查看>>
为啥程序会有bug?
查看>>
跨域技术
查看>>
JS里的居民们7-对象和数组转换
查看>>
计算两个日期的时间间隔,返回的是时间间隔的日期差的绝对值.
查看>>
python初体验
查看>>