# Python 中的 union() 函數

| |

`輸入：設 A = {2, 4, 5, 6} 並設 B = {4, 6, 7, 8 } 輸出：{2, 4, 5, 6, 7, 8} 解釋：取集合 A 和 B 的每個元素，不重複任何元素，我們得到一個新集合 = {2, 4, 5, 6, 7 , 8}。這個新集合包含集合 A 的所有元素和集合 B 的所有元素，沒有元素重複，並被命名為集合 A 和 B 的並集。`

set1.union (set2, set3, set4,Ä¶.)

union()函數返回一個集合，該集合具有所有集合（set1、set2、set3 ...）的並集set1.

` # 用於 union() 函數的 Python3 程序 `

` set1 ` ` = ` ` {` ` 2 ` `, ` ` 4 ` ` , ` ` 5 ` `, ` ` 6 ` `} `

` set2 ` ` = ` ` {` ` 4 ` `, ` ` 6 ` ` , ` ` 7 ` `, ` ` 8 ` `} `

` set3 ` ` = ` ` {` ` 7 ` `, ` ` 8 ` `, ` ` 9 ` `, ` ` 10 ` `} `

` # 合併兩個集合 `

` print ` ` (` ` "set1 U set2: "` `, set1.union (set2)) `

` `
` # 組合三個集合 `

` print ` ` (` ` "set1 U set2 U set3:" ` `, set1.union (set2, set3)) `

< /tr>

`set1 U set2: {2, 4, 5, 6, 7, 8} set1 U set2 U set3: {2, 4, 5, 6, 7, 8, 9, 10} `

## Shop

Learn programming in R: courses

\$

Best Python online courses for 2022

\$

Best laptop for Fortnite

\$

Best laptop for Excel

\$

Best laptop for Solidworks

\$

Best laptop for Roblox

\$

Best computer for crypto mining

\$

Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method