本文共 2556 字,大约阅读时间需要 8 分钟。
ntp symmetric
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/