Python Set update() Method

Python3 列表Python Set


Description

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

Syntax

The syntax of the update() method is:

set.update(set)

Parameters

  • set -- Required, can be an element or a set
  • Return Value

    None.

    Example

    Merge two sets, duplicate elements will only appear once:

    Example 1

    x = {"apple", "banana", "cherry"} y = {"google", "example", "apple"} x.update(y) print(x)

    The output result is:

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

    Python3 列表Python Set

    Other Extensions