如何添加两组? [英] How do I add two sets?

查看:30
本文介绍了如何添加两组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

a = {'a', 'b', 'c'} 
b = {'d', 'e', 'f'}

我想添加以上两个设定值.我需要像

I want to add above two set values. I need output like

c = {'a', 'b', 'c', 'd', 'e', 'f'}

推荐答案

你所要做的就是把它们结合起来

All you have to do to combine them is

c = a | b

集合是唯一值的无序序列.<代码>一个 |b 或 a.union(b) 是两个集合的并集(一个包含在任一集合中找到的所有值的新集合).这是一类称为设置操作"的操作,Python sets 提供方便的工具.

Sets are unordered sequences of unique values. a | b or a.union(b) is the union of the two sets (a new set with all values found in either set). This is a class of operation called a "set operation", which Python sets provide convenient tools for.

这篇关于如何添加两组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆