0
0

More than 3 years have passed since last update.

Python set型 集合演算

Last updated at Posted at 2021-06-22

集合演算

和(union)
積(intersection)
差(difference)

和(union) 記号 | 要素の和

union = {1,2,3,4} | {6,7,8,9}
print(union)

結果
{1, 2, 3, 4, 6, 7, 8, 9}

積(intersection) 記号 & 被っている要素

intersection = {1,2,3,4,'A'} & {4,7,8,9,'A'}
print(intersection)

結果
{4, 'A'}

差(difference)記号 & 左の集合から右の集合を引く残ったもの

difference = {1,2,3,4,5,} - {2,3,4,5,6}
print(difference)

結果
{1}

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