Easy Tutorial
❮ Ref Set Discard Python Func Eval ❯

Python Set update() Method

Python Set


Description

The update() method is used to modify the current set by adding new elements or sets to it. If an element being added already exists in the set, it will only appear once, and duplicates will be ignored.

Syntax

The syntax for the update() method is:

set.update(set)

Parameters

Return Value

None.

Example

Merging two sets, with duplicate elements appearing only once:

Example 1

x = {"apple", "banana", "cherry"}
y = {"google", "tutorialpro", "apple"}

x.update(y)

print(x)

Output result:

{'banana', 'apple', 'google', 'tutorialpro', 'cherry'}

Python Set

❮ Ref Set Discard Python Func Eval ❯