博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 示例_带有示例的Python Set union()方法
阅读量:2538 次
发布时间:2019-05-11

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

python 示例

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

union() method is used to find the union of all sets, this method is called with this set (set1) and other sets (set1, set2, ...) can be supplied as an arguments, method returns the set containing all elements of all sets (common elements repeat only once).

union()方法用于查找所有集合的并集,此方法以该集合( set1 )调用,其他集合( set1,set2,... )可以作为参数提供,方法返回包含所有元素的集合所有集合中的所有元素(常见元素仅重复一次)。

Syntax:

句法:

set1.union(set2, set3, ...)

Parameter(s):

参数:

  • set2, set3, ... – Here, set2 is required and other sets are optional.

    set2,set3,... –这里, set2是必需的,其他集合是可选的。

Return value:

返回值:

The return type of this method is <class 'set'>, it returns the set of the all elements.

该方法的返回类型为<class'set'> ,它返回所有元素的集合。

Example 1:

范例1:

# Python Set union() Method with Example# declaring the setscars_1 = {
"Porsche", "Audi", "Lexus"}cars_2 = {
"Porsche", "Mazda", "Lincoln"}# finding the union of both setsx = cars_1.union(cars_2)# print the setprint("cars_1: ", cars_1)print("cars_2: ", cars_2)print("x: ", x)

Output

输出量

cars_1:  {'Porsche', 'Audi', 'Lexus'}cars_2:  {'Porsche', 'Mazda', 'Lincoln'}x:  {'Porsche', 'Mazda', 'Lincoln', 'Audi', 'Lexus'}

Example 2:

范例2:

# Python Set union() Method with Example# declaring the setsx = {
"ABC", "PQR", "XYZ"}y = {
"ABC", "PQR", "XYZ"}z = {
"DEF", "MNO", "ABC"}# finding the union of all setsresult = x.union(y,z)# printing the setsprint("x: ", x)print("y: ", y)print("result: ", result)

Output

输出量

x:  {'ABC', 'PQR', 'XYZ'}y:  {'ABC', 'PQR', 'XYZ'}result:  {'PQR', 'MNO', 'DEF', 'ABC', 'XYZ'}

翻译自:

python 示例

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

你可能感兴趣的文章
Composite UI Application Block (CAB) 概念和术语
查看>>
64位MATLAB和C混合编程以及联合调试
查看>>
原生js大总结二
查看>>
PHP基础
查看>>
UVa 11488 超级前缀集合(Trie的应用)
查看>>
Django 翻译与 LANGUAGE_CODE
查看>>
[转]iOS教程:SQLite的创建数据库,表,插入查看数据
查看>>
【转载】OmniGraffle (一)从工具栏开始
查看>>
初识ionic
查看>>
java 中打印调用栈
查看>>
开发 笔记
查看>>
数据挖掘算法比赛 - 简单经验总结
查看>>
生成商户订单号/退款单号
查看>>
使用Android OpenGL ES 2.0绘图之六:响应触摸事件
查看>>
我们过去几年做对了哪些事
查看>>
Java Bigdecimal使用
查看>>
SQL注入之绕过WAF和Filter
查看>>
jquery validate使用方法
查看>>
DataNode 工作机制
查看>>
windows系统下安装MySQL
查看>>