0
0

python 集合型

Posted at

はじめに

下記を満たす要素の集まりを集合体と言う。
・重複する要素を持たない
・要素が順序を持たない

集合体は中括弧{}で生成。

a = {'a','a','b'}
print(a)#{'a', 'b'}
#重複する'a'が1つになっている。
演算
abcd = {'a','b','c','d'}
cdef = {'c','d','e','f'}
#和
print(abcd | cdef)#{'c', 'b', 'e', 'f', 'd', 'a'}
#積
print(abcd & cdef)#{'d', 'c'}
#差
print(abcd - cdef)#{'a', 'b'}
#対象差集合
print(abcd ^ cdef)#{'f', 'b', 'a', 'e'}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0